1#ifndef MSTL_NETWORK_HTTP_HTTP_CLIENT_MESSAGE_HPP__
2#define MSTL_NETWORK_HTTP_HTTP_CLIENT_MESSAGE_HPP__
3#include "MSTL/core/container/unordered_map.hpp"
4#include "MSTL/core/container/vector.hpp"
8struct http_client_response {
13 unordered_map<string, vector<string>> headers_;
15 vector<cookie> cookies_;
18 http_client_response() =
default;
19 http_client_response(
const http_client_response &) =
delete;
20 http_client_response &operator =(
const http_client_response &) =
delete;
21 http_client_response(http_client_response &&) noexcept = default;
22 http_client_response &operator =(http_client_response &&) noexcept = default;
24 void set_version(
string v) noexcept { version_ =
_MSTL move(v); }
25 void set_status(
const HTTP_STATUS s)
noexcept { status_ = s; }
26 void set_status_msg(
string msg)
noexcept { status_msg_ =
_MSTL move(msg); }
28 void add_header(
const string& key,
string value) {
29 headers_[key].push_back(
_MSTL move(value));
31 MSTL_NODISCARD
const string& header(
const string &key)
const noexcept {
32 static const string empty;
33 const auto it = headers_.find(key);
34 if (it == headers_.end() || it->second.empty())
return empty;
37 MSTL_NODISCARD
const vector<string>& headers(
const string &key)
const noexcept {
38 static vector<string>
empty;
39 const auto it = headers_.find(key);
40 return it != headers_.end() ? it->second :
empty;
42 MSTL_NODISCARD
const unordered_map<string, vector<string>>&
43 all_headers() const noexcept {
47 void append_body(
string b) { body_ +=
_MSTL move(b); }
48 MSTL_NODISCARD
const string& body() const noexcept {
return body_; }
50 void append_cookie(cookie c) { cookies_.push_back(
_MSTL move(c)); }
51 MSTL_NODISCARD
const vector<cookie>& cookies() const noexcept {
return cookies_; }
53 MSTL_NODISCARD
const string& version() const noexcept {
return version_; }
54 MSTL_NODISCARD HTTP_STATUS status() const noexcept {
return status_; }
55 MSTL_NODISCARD
const string& status_msg() const noexcept {
return status_msg_; }
58struct http_client_request {
59 HTTP_METHOD method = HTTP_METHOD::GET;
63 string version =
"HTTP/1.1";
64 unordered_map<string, string> headers;
67 explicit http_client_request(
string h,
const uint16_t p = 80)
70 void set_header(
const string& key,
string value) { headers[key] =
_MSTL move(value); }
71 void set_body(
string b) { body =
_MSTL move(b); }
72 void set_method(HTTP_METHOD m) { method =
_MSTL move(m); }
unsigned short uint16_t
16位无符号整数类型
#define _MSTL
全局命名空间MSTL前缀
#define MSTL_END_NAMESPACE__
结束全局命名空间MSTL
#define MSTL_BEGIN_NAMESPACE__
开始全局命名空间MSTL
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result)
移动范围元素
MSTL_NODISCARD MSTL_ALWAYS_INLINE constexpr bool empty(const Container &cont) noexcept(noexcept(cont.empty()))
检查容器是否为空