1#ifndef NEFORCE_NETWORK_HTTP_HTTP_SERVER_MESSAGE_HPP__
2#define NEFORCE_NETWORK_HTTP_HTTP_SERVER_MESSAGE_HPP__
22#include "NeForce/core/container/buffer_chain.hpp"
25NEFORCE_BEGIN_NAMESPACE__
103 return it !=
parameters.end() ? it->second.view() :
"";
126 const auto it =
cookies.find(name);
127 return it !=
cookies.end() ? it->second.view() :
"";
150 const auto it =
headers.find(name);
151 return it !=
headers.end() ? it->second.view() :
"";
185 const auto conn =
header(http_key::Connection());
187 if (conn_lower ==
"close") {
191 if (!
version.starts_with(
"HTTP/1.0")) {
224 NEFORCE_NODISCARD
bool is_ajax()
const {
return header(
"X-Requested-With") ==
"XMLHttpRequest"; }
311 const auto it =
headers.find(name);
312 return it !=
headers.end() ? it->second.view() :
"";
374NEFORCE_END_NAMESPACE__
constexpr bool starts_with(const basic_string &other) const noexcept
检查是否以另一个字符串开头
constexpr basic_string & lowercase() noexcept(noexcept(_NEFORCE transform(begin(), end(), begin(), _NEFORCE to_lowercase< CharT >)))
转换为小写
http_server_response http_response
HTTP响应类型别名
http_server_request http_request
HTTP请求类型别名
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
basic_string< char > string
字符字符串
basic_string_view< char > string_view
字符字符串视图
@ S4_NOT_FOUND
404 Not Found 请求的资源不存在
unordered_map< string, any > http_context
请求上下文,跨过滤器/中间件传递任意数据
static const http_content & PLAIN_TEXT()
text/plain
static const http_method & GET()
GET方法
string_view user_agent() const
获取User-Agent
string_view content_type() const
获取Content-Type
unordered_map< string, string > trailers
Trailer头部
bool has_header(const string &name) const
检查请求头是否存在
string_view cookie(const string &name) const
获取Cookie值
unordered_map< string, string > cookies
Cookie
void set_parameter(const string &name, string value)
设置参数
void set_cookie(const string &name, string value)
设置Cookie值
string_view client_ip() const
获取客户端真实IP
string_view referer() const
获取Referer
bool is_keep_alive() const
检查是否为Keep-Alive连接
unordered_map< string, string > parameters
请求参数
string to_string() const
序列化为HTTP请求字符串
string_view parameter(const string &name) const
获取参数值
bool has_parameter(const string &name) const
检查参数是否存在
unordered_map< string, string > form_data
表单数据
void set_header(const string &name, string value)
设置请求头
string_view header(const string &name) const
获取请求头值
bool has_session() const noexcept
检查是否有关联的有效会话
http_context context
请求上下文
bool is_ajax() const
检查是否为AJAX请求
http_session * session
会话对象
static http_server_request parse(string_view str)
从字符串解析HTTP请求
unordered_map< string, string > headers
请求头
bool has_cookie(const string &name) const
检查Cookie是否存在
string status_message
状态消息
unordered_map< string, string > headers
响应头
http_server_response()
默认构造函数
bool has_header(const string &name) const
检查响应头是否存在
string redirect_url
重定向URL
void set_content_type(http_content value)
设置Content-Type
string build_header_string() const
构建响应头字符串
vector< http_cookie > cookies
设置的Cookie
string_view header(const string &name) const
获取响应头值
void set_header(const string &name, string value)
设置响应头
unordered_map< string, string > trailers
Trailer头部
http_status status
HTTP状态码
string to_string() const
序列化为HTTP响应字符串
bool chunked_encoding
是否使用chunked传输编码
void set_content_type(string value)
设置Content-Type