11#include <promeki/config.h>
12#if PROMEKI_ENABLE_HTTP
25PROMEKI_NAMESPACE_BEGIN
64 PROMEKI_SHARED_FINAL(HttpRequest)
67 using Ptr = SharedPtr<HttpRequest>;
70 using List = ::promeki::List<HttpRequest>;
73 using PtrList = ::promeki::List<Ptr>;
76 static const String DefaultHttpVersion;
79 HttpRequest() =
default;
82 const HttpMethod &method()
const {
return _method; }
85 void setMethod(
const HttpMethod &m) { _method = m; }
95 const Url &url()
const {
return _url; }
98 void setUrl(
const Url &u) { _url = u; }
101 const String &path()
const {
return _url.path(); }
104 String queryValue(
const String &key,
const String &defaultValue = String())
const {
105 return _url.queryValue(key, defaultValue);
109 const HttpHeaders &headers()
const {
return _headers; }
112 HttpHeaders &headers() {
return _headers; }
115 void setHeaders(
const HttpHeaders &h) { _headers = h; }
118 String header(
const String &name,
const String &defaultValue = String())
const {
119 return _headers.value(name, defaultValue);
123 const Buffer &body()
const {
return _body; }
126 void setBody(
const Buffer &body) { _body = body; }
134 void setBody(
const String &text);
144 String bodyAsString()
const;
154 JsonObject bodyAsJson(Error *err =
nullptr)
const;
164 JsonArray bodyAsJsonArray(Error *err =
nullptr)
const;
172 void setBody(
const JsonObject &obj);
175 void setBody(
const JsonArray &arr);
178 const HashMap<String, String> &pathParams()
const {
return _pathParams; }
181 void setPathParams(
const HashMap<String, String> ¶ms) { _pathParams = params; }
188 String pathParam(
const String &name,
const String &defaultValue = String())
const {
189 return _pathParams.value(name, defaultValue);
199 const String &httpVersion()
const {
return _httpVersion; }
202 void setHttpVersion(
const String &v) { _httpVersion = v; }
211 const String &peerAddress()
const {
return _peerAddress; }
214 void setPeerAddress(
const String &s) { _peerAddress = s; }
217 bool operator==(
const HttpRequest &other)
const;
220 bool operator!=(
const HttpRequest &other)
const {
return !(*
this == other); }
225 HttpHeaders _headers;
227 HashMap<String, String> _pathParams;
228 String _httpVersion = DefaultHttpVersion;