11#include <promeki/config.h>
12#if PROMEKI_ENABLE_HTTP
26PROMEKI_NAMESPACE_BEGIN
65 PROMEKI_SHARED_FINAL(HttpRequest)
68 using Ptr = SharedPtr<HttpRequest>;
71 using List = ::promeki::List<HttpRequest>;
74 using PtrList = ::promeki::List<Ptr>;
77 static const String DefaultHttpVersion;
80 HttpRequest() =
default;
83 const HttpMethod &method()
const {
return _method; }
86 void setMethod(
const HttpMethod &m) { _method = m; }
96 const Url &url()
const {
return _url; }
99 void setUrl(
const Url &u) { _url = u; }
102 const String &path()
const {
return _url.path(); }
105 String queryValue(
const String &key,
const String &defaultValue = String())
const {
106 return _url.queryValue(key, defaultValue);
110 const HttpHeaders &headers()
const {
return _headers; }
113 HttpHeaders &headers() {
return _headers; }
116 void setHeaders(
const HttpHeaders &h) { _headers = h; }
119 String header(
const String &name,
const String &defaultValue = String())
const {
120 return _headers.value(name, defaultValue);
124 const Buffer &body()
const {
return _body; }
127 void setBody(
const Buffer &body) { _body = body; }
135 void setBody(
const String &text);
145 String bodyAsString()
const;
155 JsonObject bodyAsJson(Error *err =
nullptr)
const;
165 JsonArray bodyAsJsonArray(Error *err =
nullptr)
const;
173 void setBody(
const JsonObject &obj);
176 void setBody(
const JsonArray &arr);
195 using BodySink = ::promeki::Function<Error(
const void *data,
size_t len)>;
213 using ProgressCallback = ::promeki::Function<bool(int64_t received, int64_t total)>;
216 const BodySink &bodySink()
const {
return _bodySink; }
225 void setBodySink(BodySink sink) { _bodySink = std::move(sink); }
228 const ProgressCallback &progressCallback()
const {
return _progressCallback; }
236 void setProgressCallback(ProgressCallback cb) { _progressCallback = std::move(cb); }
239 const HashMap<String, String> &pathParams()
const {
return _pathParams; }
242 void setPathParams(
const HashMap<String, String> ¶ms) { _pathParams = params; }
249 String pathParam(
const String &name,
const String &defaultValue = String())
const {
250 return _pathParams.value(name, defaultValue);
260 const String &httpVersion()
const {
return _httpVersion; }
263 void setHttpVersion(
const String &v) { _httpVersion = v; }
272 const String &peerAddress()
const {
return _peerAddress; }
275 void setPeerAddress(
const String &s) { _peerAddress = s; }
278 bool operator==(
const HttpRequest &other)
const;
281 bool operator!=(
const HttpRequest &other)
const {
return !(*
this == other); }
286 HttpHeaders _headers;
288 HashMap<String, String> _pathParams;
289 String _httpVersion = DefaultHttpVersion;
292 ProgressCallback _progressCallback;