Repos
C++
1.1 KB46 lines Opens in site
Directory
Raw
Download
#pragma once
// Spec: SPEC.md FR-NET-01. Plain data describing one HTTP exchange.
#include <atomic>
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "core/Result.hpp"
namespace dp {
struct HttpRequest {
std::string method = "GET";
// Relative to spec::NetLimits::kBaseUrl unless it starts with http:// or https://.
std::string path;
std::vector<std::pair<std::string, std::string>> query;
std::vector<std::pair<std::string, std::string>> headers;
std::string body;
std::string contentType;
double timeoutSeconds = 0.0; // 0 = spec default
int maxRetries = -1; // -1 = spec default for the method (GET only)
std::size_t maxResponseBytes = 0; // 0 = spec default
};
struct HttpResponse {
int status = 0;
std::string body;
std::string contentType;
};
class CancelToken {
public:
void cancel() { cancelled_.store(true); }
bool cancelled() const { return cancelled_.load(); }
private:
std::atomic<bool> cancelled_{false};
};
using CancelPtr = std::shared_ptr<CancelToken>;
using HttpCallback = std::function<void(Result<HttpResponse>)>;
} // namespace dp