14 auto to_lower(std::string str) -> std::string
16 std::transform(str.begin(), str.end(), str.begin(),
17 [](
unsigned char c) { return std::tolower(c); });
26 auto lower_name = to_lower(name);
27 for (
const auto& [key, value] : headers)
29 if (to_lower(key) == lower_name)
40 auto lower_name = to_lower(name);
41 for (
auto it = headers.begin(); it != headers.end();)
43 if (to_lower(it->first) == lower_name)
45 it = headers.erase(it);
54 headers[name] = value;
59 return std::string(
body.begin(),
body.end());
64 body.assign(content.begin(), content.end());
71 auto lower_name = to_lower(name);
72 for (
const auto& [key, value] : headers)
74 if (to_lower(key) == lower_name)
85 auto lower_name = to_lower(name);
86 for (
auto it = headers.begin(); it != headers.end();)
88 if (to_lower(it->first) == lower_name)
90 it = headers.erase(it);
99 headers[name] = value;
104 return std::string(
body.begin(),
body.end());
109 body.assign(content.begin(), content.end());
127 default:
return "GET";
133 auto upper_method = method_str;
134 std::transform(upper_method.begin(), upper_method.end(), upper_method.begin(),
135 [](
unsigned char c) { return std::toupper(c); });
147 return ::kcenon::network::error<http_method>(
149 "Unknown HTTP method: " + method_str,
160 default:
return "HTTP/1.1";
171 return ::kcenon::network::error<http_version>(
173 "Unknown HTTP version: " + version_str,
182 case 100:
return "Continue";
183 case 101:
return "Switching Protocols";
186 case 200:
return "OK";
187 case 201:
return "Created";
188 case 202:
return "Accepted";
189 case 203:
return "Non-Authoritative Information";
190 case 204:
return "No Content";
191 case 205:
return "Reset Content";
192 case 206:
return "Partial Content";
195 case 300:
return "Multiple Choices";
196 case 301:
return "Moved Permanently";
197 case 302:
return "Found";
198 case 303:
return "See Other";
199 case 304:
return "Not Modified";
200 case 307:
return "Temporary Redirect";
201 case 308:
return "Permanent Redirect";
204 case 400:
return "Bad Request";
205 case 401:
return "Unauthorized";
206 case 402:
return "Payment Required";
207 case 403:
return "Forbidden";
208 case 404:
return "Not Found";
209 case 405:
return "Method Not Allowed";
210 case 406:
return "Not Acceptable";
211 case 407:
return "Proxy Authentication Required";
212 case 408:
return "Request Timeout";
213 case 409:
return "Conflict";
214 case 410:
return "Gone";
215 case 411:
return "Length Required";
216 case 412:
return "Precondition Failed";
217 case 413:
return "Payload Too Large";
218 case 414:
return "URI Too Long";
219 case 415:
return "Unsupported Media Type";
220 case 416:
return "Range Not Satisfiable";
221 case 417:
return "Expectation Failed";
222 case 429:
return "Too Many Requests";
225 case 500:
return "Internal Server Error";
226 case 501:
return "Not Implemented";
227 case 502:
return "Bad Gateway";
228 case 503:
return "Service Unavailable";
229 case 504:
return "Gateway Timeout";
230 case 505:
return "HTTP Version Not Supported";
232 default:
return "Unknown";
242 result +=
"; Path=" +
path;
245 result +=
"; Domain=" +
domain;
248 result +=
"; Expires=" +
expires;
251 result +=
"; Max-Age=" + std::to_string(
max_age);
254 result +=
"; HttpOnly";
257 result +=
"; Secure";
268 const std::string& path,
int max_age,
269 bool http_only,
bool secure,
270 const std::string& same_site) ->
void
280 set_cookies.push_back(c);
constexpr int invalid_argument
auto http_version_to_string(http_version version) -> std::string
Convert HTTP version enum to string.
auto string_to_http_method(const std::string &method_str) -> ::kcenon::network::internal::Result< http_method >
Convert string to HTTP method enum.
http_version
HTTP protocol version.
auto http_method_to_string(http_method method) -> std::string
Convert HTTP method enum to string.
auto string_to_http_version(const std::string &version_str) -> ::kcenon::network::internal::Result< http_version >
Convert string to HTTP version enum.
auto get_status_message(int status_code) -> std::string
Get HTTP status message for a status code.
http_method
HTTP request methods (verbs)
constexpr const char * version() noexcept
Get the network system version string.
Represents an HTTP cookie.
auto to_header_value() const -> std::string
Convert cookie to Set-Cookie header value.
std::vector< uint8_t > body
auto get_body_string() const -> std::string
Get body as string.
auto set_body_string(const std::string &content) -> void
Set body from string.
auto set_header(const std::string &name, const std::string &value) -> void
Set a header value.
auto get_header(const std::string &name) const -> std::optional< std::string >
Get the value of a header (case-insensitive)
auto set_cookie(const std::string &name, const std::string &value, const std::string &path="/", int max_age=-1, bool http_only=true, bool secure=false, const std::string &same_site="") -> void
Set a cookie in the response.
auto set_body_string(const std::string &content) -> void
Set body from string.
auto set_header(const std::string &name, const std::string &value) -> void
Set a header value.
auto get_header(const std::string &name) const -> std::optional< std::string >
Get the value of a header (case-insensitive)
std::vector< uint8_t > body
auto get_body_string() const -> std::string
Get body as string.