1#ifndef MSTL_NETWORK_HTTP_HTTP_CLIENT_HPP__
2#define MSTL_NETWORK_HTTP_HTTP_CLIENT_HPP__
3#include "../dns/dns_client.hpp"
4#include "../tcp_client.hpp"
6#include "http_client_message.hpp"
9class MSTL_API http_client {
12 unordered_map<string, cookie> cookie_jar_;
15 string build_request_str(
const http_client_request& req,
const url& req_url)
const;
16 bool send_request(string_view request_str);
17 bool read_response(
string& out_data)
const;
18 static bool parse_response(string_view resp_str, http_client_response& resp);
20 static cookie parse_set_cookie(string_view str,
string default_domain,
string default_path) ;
21 void update_cookies(
const vector<cookie>& resp_cookies,
const url& request_url);
22 string build_cookie_header(
const url& request_url)
const;
24 static bool parse_chunked_body(string_view chunked,
string& decoded);
27 explicit http_client() =
default;
28 explicit http_client(dns_client dns) : client_(
_MSTL move(dns)) {}
29#ifdef MSTL_SUPPORT_OPENSSL__
30 explicit http_client(ssl_context ctx) : client_(
_MSTL move(ctx)) {}
32 ~http_client() =
default;
35#ifdef MSTL_SUPPORT_OPENSSL__
36 void set_ssl_context(ssl_context ctx) { client_.set_ssl_context(
_MSTL move(ctx)); }
39 MSTL_NODISCARD http_client_response request(http_client_request req);
41 void close() noexcept { client_.close(); }
constexpr const T & max(const T &a, const T &b, Compare comp) noexcept(noexcept(comp(a, b)))
返回两个值中的较大者
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)
移动范围元素