commit
d002c528f5
5 files changed
+1510
No files matched your search
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include <Void/Net/Http.hpp>
|
||||
#include <Void/ShortUrl/ShortUrl.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace Echoion::Plugins::ShortUrl
|
||||
{
|
||||
enum class ExternalEncoding { query, json, form };
|
||||
enum class ExternalResponseKind { plain, header, jsonPointer };
|
||||
|
||||
struct ExternalFieldTemplate {
|
||||
std::string name;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
struct ExternalHeaderTemplate {
|
||||
std::string name;
|
||||
std::string value;
|
||||
bool sensitive{};
|
||||
};
|
||||
|
||||
struct ExternalResponseConfig {
|
||||
ExternalResponseKind kind{ExternalResponseKind::jsonPointer};
|
||||
std::string selector{"/shortUrl"};
|
||||
};
|
||||
|
||||
struct ExternalConfig {
|
||||
std::string endpoint;
|
||||
Void::Net::Method method{Void::Net::Method::Post};
|
||||
ExternalEncoding encoding{ExternalEncoding::json};
|
||||
std::vector<ExternalFieldTemplate> fields;
|
||||
std::vector<ExternalHeaderTemplate> headers;
|
||||
ExternalResponseConfig response;
|
||||
bool allowHttp{};
|
||||
bool allowPrivateHosts{};
|
||||
bool allowPrivateTargets{};
|
||||
bool allowCrossHostRedirects{};
|
||||
int maxRedirects{};
|
||||
std::uint32_t timeoutSeconds{3};
|
||||
std::size_t maximumResponseBytes{64U * 1024U};
|
||||
std::size_t cacheCapacity{512};
|
||||
std::uint32_t cacheTtlSeconds{3600};
|
||||
std::size_t maximumConcurrency{4};
|
||||
};
|
||||
|
||||
[[nodiscard]] std::expected<ExternalConfig, std::string>
|
||||
parseExternalConfig(std::string_view payload);
|
||||
|
||||
class ExternalShortener
|
||||
{
|
||||
public:
|
||||
|
||||
[[nodiscard]] static std::expected<
|
||||
std::unique_ptr<ExternalShortener>, std::string>
|
||||
create(ExternalConfig config);
|
||||
|
||||
~ExternalShortener();
|
||||
ExternalShortener(const ExternalShortener&) = delete;
|
||||
ExternalShortener& operator=(const ExternalShortener&) = delete;
|
||||
|
||||
[[nodiscard]] Void::ShortUrl::Health health() const;
|
||||
[[nodiscard]] Void::ShortUrl::ShortenResult
|
||||
shorten(const Void::ShortUrl::ShortenRequest& request);
|
||||
|
||||
/// Pure request/extraction seams used by focused tests and provider
|
||||
/// configuration diagnostics. They never perform network I/O.
|
||||
[[nodiscard]] std::expected<Void::Net::Request, std::string>
|
||||
previewRequest(std::string_view targetUrl) const;
|
||||
[[nodiscard]] std::expected<std::string, std::string>
|
||||
previewExtract(const Void::Net::Response& response) const;
|
||||
|
||||
private:
|
||||
|
||||
struct ConstructionToken {
|
||||
explicit ConstructionToken() = default;
|
||||
};
|
||||
struct Impl;
|
||||
|
||||
public:
|
||||
|
||||
ExternalShortener(ConstructionToken, ExternalConfig config);
|
||||
|
||||
private:
|
||||
|
||||
std::unique_ptr<Impl> impl_;
|
||||
};
|
||||
|
||||
} // namespace Echoion::Plugins::ShortUrl
|
||||
Reference in new issue
Block a user