68 lines
2.0 KiB
C++
68 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <Void/Net/Http.hpp>
|
|
#include <Void/ShortUrl/V2.hpp>
|
|
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::ShortUrl::V2
|
|
{
|
|
struct RemoteCapabilities {
|
|
bool supports_custom_key{true};
|
|
bool supports_expiry{true};
|
|
bool supports_resolve{true};
|
|
bool supports_revoke{true};
|
|
};
|
|
|
|
struct RemoteProviderOptions {
|
|
std::string base_url{};
|
|
std::string provider_id{"void.remote"};
|
|
RemoteCapabilities capabilities{};
|
|
Void::Net::HttpClientOptions http_options{
|
|
.verify_tls = true,
|
|
.max_body_size = 1024ULL * 1024,
|
|
};
|
|
std::chrono::seconds timeout{std::chrono::seconds{10}};
|
|
std::uint64_t max_response_bytes{1024ULL * 1024};
|
|
std::vector<Void::Net::Header> headers{};
|
|
};
|
|
|
|
/// Generic remote ShortUrl V2 provider over `Void::Net::HttpClient`.
|
|
/// Checks capability flags before network mutation, enforces response size
|
|
/// and deadline bounds, preserves Retry-After, and maps lost-reply
|
|
/// transport failures after send to `V2ErrorCode::UnknownOutcome`.
|
|
class RemoteProvider final : public Provider
|
|
{
|
|
public:
|
|
|
|
explicit RemoteProvider(RemoteProviderOptions options);
|
|
|
|
[[nodiscard]] std::string_view
|
|
provider_id() const noexcept override;
|
|
[[nodiscard]] V1::Health health() const override;
|
|
[[nodiscard]] bool supports_resolve() const noexcept override;
|
|
|
|
[[nodiscard]] Void::Result::Result<Link>
|
|
shorten(const CreateLink& request,
|
|
const ShortenOptions& options = {}) override;
|
|
[[nodiscard]] Void::Result::Result<Link>
|
|
resolve(std::string_view key) override;
|
|
[[nodiscard]] Void::Result::Result<void>
|
|
revoke(std::string_view key) override;
|
|
|
|
/// Retry-After seconds from the most recent rate-limited/unavailable
|
|
/// remote response (0 if absent).
|
|
[[nodiscard]] std::uint32_t last_retry_after_seconds() const noexcept;
|
|
|
|
private:
|
|
|
|
RemoteProviderOptions m_options;
|
|
Void::Net::HttpClient m_client;
|
|
std::atomic<std::uint32_t> m_last_retry_after{0};
|
|
};
|
|
|
|
} // namespace Void::ShortUrl::V2
|