NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
http_constants.hpp
浏览该文件的文档.
1#ifndef NEFORCE_NETWORK_HTTP_CONSTANTS_HPP__
2#define NEFORCE_NETWORK_HTTP_CONSTANTS_HPP__
3
15
17NEFORCE_BEGIN_NAMESPACE__
18
24
30NEFORCE_ERROR_BUILD_FINAL_CLASS(http_exception, network_exception, "Http Actions Failed");
31 // Exceptions
33
34NEFORCE_BEGIN_HTTP__
35
41
204
205NEFORCE_API string http_status_message(http_status status);
206
207NEFORCE_API http_status http_status_from_code(uint16_t code) noexcept;
208
209
216struct NEFORCE_API http_content : istringify<http_content> {
217private:
218 string content_{"UNKNOWN"};
219
220public:
221 http_content() = default;
222 http_content(const http_content&) = default;
223 http_content& operator=(const http_content&) = default;
224
229 http_content(http_content&& other) noexcept :
230 content_(_NEFORCE move(other.content_)) {}
231
237 http_content& operator=(http_content&& other) noexcept {
238 if (addressof(other) == this) {
239 return *this;
240 }
241 content_ = _NEFORCE move(other.content_);
242 return *this;
243 }
244
249 explicit http_content(const string& content) :
250 content_(content) {}
251
257 http_content& operator=(const string& content) {
258 content_ = content;
259 return *this;
260 }
261
262 ~http_content() = default;
263
264 static const http_content& HTML_TEXT();
265 static const http_content& XML_TEXT();
266 static const http_content& CSS_TEXT();
267 static const http_content& PLAIN_TEXT();
268 static const http_content& JSON_APP();
269 static const http_content& FORM_APP();
270 static const http_content& JPEG_IMG();
271 static const http_content& PNG_IMG();
272 static const http_content& BMP_IMG();
273 static const http_content& WEBP_IMG();
274 static const http_content& HTML_MSG();
275
276 NEFORCE_NODISCARD bool is_html_text() const { return content_ == HTML_TEXT().content_; }
277 NEFORCE_NODISCARD bool is_xml_text() const { return content_ == XML_TEXT().content_; }
278 NEFORCE_NODISCARD bool is_css_text() const { return content_ == CSS_TEXT().content_; }
279 NEFORCE_NODISCARD bool is_plain_text() const { return content_ == PLAIN_TEXT().content_; }
280 NEFORCE_NODISCARD bool is_json_app() const { return content_ == JSON_APP().content_; }
281 NEFORCE_NODISCARD bool is_form_app() const { return content_ == FORM_APP().content_; }
282 NEFORCE_NODISCARD bool is_jpeg_img() const { return content_ == JPEG_IMG().content_; }
283 NEFORCE_NODISCARD bool is_png_img() const { return content_ == PNG_IMG().content_; }
284 NEFORCE_NODISCARD bool is_bmp_img() const { return content_ == BMP_IMG().content_; }
285 NEFORCE_NODISCARD bool is_webp_img() const { return content_ == WEBP_IMG().content_; }
286 NEFORCE_NODISCARD bool is_html_msg() const { return content_ == HTML_MSG().content_; }
287
288 NEFORCE_NODISCARD static bool is_html_text(const string_view view) { return view == HTML_TEXT().content_; }
289 NEFORCE_NODISCARD static bool is_xml_text(const string_view view) { return view == XML_TEXT().content_; }
290 NEFORCE_NODISCARD static bool is_css_text(const string_view view) { return view == CSS_TEXT().content_; }
291 NEFORCE_NODISCARD static bool is_plain_text(const string_view view) { return view == PLAIN_TEXT().content_; }
292 NEFORCE_NODISCARD static bool is_json_app(const string_view view) { return view == JSON_APP().content_; }
293 NEFORCE_NODISCARD static bool is_form_app(const string_view view) { return view == FORM_APP().content_; }
294 NEFORCE_NODISCARD static bool is_jpeg_img(const string_view view) { return view == JPEG_IMG().content_; }
295 NEFORCE_NODISCARD static bool is_png_img(const string_view view) { return view == PNG_IMG().content_; }
296 NEFORCE_NODISCARD static bool is_bmp_img(const string_view view) { return view == BMP_IMG().content_; }
297 NEFORCE_NODISCARD static bool is_webp_img(const string_view view) { return view == WEBP_IMG().content_; }
298 NEFORCE_NODISCARD static bool is_html_msg(const string_view view) { return view == HTML_MSG().content_; }
299
304 NEFORCE_NODISCARD const string& content() const& noexcept { return content_; }
305
310 NEFORCE_NODISCARD string content() && noexcept { return _NEFORCE move(content_); }
311
316 NEFORCE_NODISCARD string to_string() const { return content_; }
317};
318
319
320#ifdef DELETE
321# undef DELETE
322#endif
323
330struct NEFORCE_API http_method : istringify<http_method> {
331private:
332 string method_{"UNKNOWN"};
333
334public:
335 http_method() = default;
336 http_method(const http_method&) = default;
337 http_method& operator=(const http_method&) = default;
338
343 http_method(http_method&& other) noexcept :
344 method_(_NEFORCE move(other.method_)) {}
345
351 http_method& operator=(http_method&& other) noexcept {
352 if (_NEFORCE addressof(other) == this) {
353 return *this;
354 }
355 method_ = _NEFORCE move(other.method_);
356 return *this;
357 }
358
363 explicit http_method(const string& method) :
364 method_(method) {}
365
371 http_method& operator=(const string& method) {
372 method_ = method;
373 return *this;
374 }
375
380 explicit http_method(string&& method) :
381 method_(_NEFORCE move(method)) {}
382
388 http_method& operator=(string&& method) {
389 method_ = _NEFORCE move(method);
390 return *this;
391 }
392
393 ~http_method() = default;
394
395 static const http_method& GET();
396 static const http_method& POST();
397 static const http_method& HEAD();
398 static const http_method& PUT();
399 static const http_method& DELETE();
400 static const http_method& OPTIONS();
401 static const http_method& TRACE();
402 static const http_method& CONNECT();
403 static const http_method& PATCH();
404 static const http_method& DEFAULT();
405
410 NEFORCE_NODISCARD const string& method() const& noexcept { return method_; }
411
416 NEFORCE_NODISCARD string method() && noexcept { return _NEFORCE move(method_); }
417
425 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) const& {
426 return http_method(method_ + ", " + rhs.method_);
427 }
428
429 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) const& {
430 return http_method(method_ + ", " + _NEFORCE move(rhs.method_));
431 }
432
433 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) && {
434 return http_method(_NEFORCE move(method_) + ", " + rhs.method_);
435 }
436
437 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) && {
438 return http_method(_NEFORCE move(method_) + ", " + _NEFORCE move(rhs.method_));
439 }
440
441 NEFORCE_NODISCARD bool is_get() const { return method_ == GET().method_; }
442 NEFORCE_NODISCARD bool is_post() const { return method_ == POST().method_; }
443 NEFORCE_NODISCARD bool is_head() const { return method_ == HEAD().method_; }
444 NEFORCE_NODISCARD bool is_put() const { return method_ == PUT().method_; }
445 NEFORCE_NODISCARD bool is_delete() const { return method_ == DELETE().method_; }
446 NEFORCE_NODISCARD bool is_options() const { return method_ == OPTIONS().method_; }
447 NEFORCE_NODISCARD bool is_trace() const { return method_ == TRACE().method_; }
448 NEFORCE_NODISCARD bool is_connect() const { return method_ == CONNECT().method_; }
449 NEFORCE_NODISCARD bool is_patch() const { return method_ == PATCH().method_; }
450
455 NEFORCE_NODISCARD string to_string() const { return method_; }
456};
457
458
465struct NEFORCE_API http_cookie_name : istringify<http_cookie_name> {
466private:
467 string cookie_{"UNKNOWN"};
468
469public:
470 http_cookie_name() = default;
471 http_cookie_name(const http_cookie_name&) = default;
472 http_cookie_name& operator=(const http_cookie_name&) = default;
473
478 http_cookie_name(http_cookie_name&& other) noexcept :
479 cookie_(_NEFORCE move(other.cookie_)) {}
480
486 http_cookie_name& operator=(http_cookie_name&& other) noexcept {
487 if (_NEFORCE addressof(other) == this) {
488 return *this;
489 }
490 cookie_ = _NEFORCE move(other.cookie_);
491 return *this;
492 }
493
498 explicit http_cookie_name(const string& cookie) :
499 cookie_(cookie) {}
500
506 http_cookie_name& operator=(const string& cookie) {
507 cookie_ = cookie;
508 return *this;
509 }
510
511 ~http_cookie_name() = default;
512
513 static const http_cookie_name& JSESSIONID();
514 static const http_cookie_name& SESSIONID();
515 static const http_cookie_name& PHPSESSID();
516 static const http_cookie_name& ASPSESSIONID();
517
522 NEFORCE_NODISCARD const string& cookie_name() const& noexcept { return cookie_; }
523
528 NEFORCE_NODISCARD string cookie_name() && noexcept { return _NEFORCE move(cookie_); }
529
534 NEFORCE_NODISCARD string to_string() const { return cookie_; }
535};
536
537
538struct NEFORCE_API http_key {
539 static const string& Access_Control_Allow_Credentials();
540 static const string& Access_Control_Allow_Headers();
541 static const string& Access_Control_Allow_Methods();
542 static const string& Access_Control_Allow_Origin();
543 static const string& Access_Control_Max_Age();
544 static const string& Connection();
545 static const string& Content_Length();
546 static const string& Content_Type();
547 static const string& Lax();
548 static const string& Strict();
549 static const string& X_Forwarded_Proto();
550};
551 // Http
553
554NEFORCE_END_HTTP__
555NEFORCE_END_NAMESPACE__
556#endif // NEFORCE_NETWORK_HTTP_CONSTANTS_HPP__
NEFORCE_NODISCARD constexpr T * addressof(T &x) noexcept
获取对象的地址
unsigned short uint16_t
16位无符号整数类型
#define NEFORCE_ERROR_BUILD_FINAL_CLASS(THIS, BASE, INFO)
构建最终异常类宏
http_status
HTTP状态码枚举
@ S5_INTERNAL_ERROR
500 Internal Server Error 服务器内部错误
@ S5_GATEWAY_TIMEOUT
504 Gateway Timeout 上游服务器响应超时
@ S3_NO_MODIFIED
304 Not Modified 资源未修改,可使用本地缓存
@ S5_BAD_GATEWAY
502 Bad Gateway 上游服务器响应无效
@ S4_MANY_REQUESTS
429 Too Many Requests 请求次数过多
@ S4_UNAUTHORIZED
401 Unauthorized 需要身份验证
@ S5_HTTP_VERSION_NOT_SUPPORT
505 HTTP Version Not Supported 不支持的HTTP版本
@ S4_METHOD_NOT_ALLOWED
405 Method Not Allowed 请求方法不允许
@ S4_FORBIDDEN
403 Forbidden 服务器拒绝请求
@ S1_CONTINUE
100 Continue 服务器收到请求头,客户端可以继续发送请求体
@ S4_PAYLOAD_LARGE
413 Payload Too Large 请求体过大
@ S4_URL_LONG
414 URI Too Long 请求URL过长
@ S2_CREATED
201 Created 请求成功并创建了新资源
@ S2_PARTIAL_CONTENT
206 Partial Content 部分请求成功(范围请求)
@ S3_MOVED_PERMANENT
301 Moved Permanently 资源已永久迁移到新URL
@ S4_NOT_FOUNT
404 Not Found 请求的资源不存在
@ S1_SWITCH_PROTOCOL
101 Switching Protocols 同意切换协议
@ S5_SERVICE_UNAVAILABLE
503 Service Unavailable 服务暂时不可用
@ S2_NO_CONTENT
204 No Content 请求成功但无内容返回
@ S2_OK
200 OK 请求成功
@ S3_FOUND
302 Found 资源临时迁移到新URL
@ S4_BAD_REQUEST
400 Bad Request 请求格式错误
@ S3_TEMPORARY_REDIRECT
307 Temporary Redirect 临时重定向
@ S3_PERMANENT_REDIRECT
308 Permanent Redirect 永久重定向
@ S4_REQUEST_TIMEOUT
408 Request Timeout 客户端请求超时
@ TRACE
跟踪级别,最详细的调试信息
@ DELETE
DELETE删除
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
basic_string_view< char > string_view
字符字符串视图
可字符串化接口
HTTP内容类型定义
static const http_content & FORM_APP()
application/x-www-form-urlencoded
http_content & operator=(http_content &&other) noexcept
移动赋值运算符
static const http_content & XML_TEXT()
text/xml
static const http_content & PLAIN_TEXT()
text/plain
static const http_content & JSON_APP()
application/json
static const http_content & JPEG_IMG()
image/jpeg
http_content(const string &content)
字符串构造函数
http_content(http_content &&other) noexcept
移动构造函数
static const http_content & HTML_MSG()
message/html
static const http_content & HTML_TEXT()
text/html
http_content & operator=(const string &content)
字符串赋值运算符
NEFORCE_NODISCARD string to_string() const
转换为字符串
static const http_content & WEBP_IMG()
image/webp
static const http_content & CSS_TEXT()
text/css
static const http_content & BMP_IMG()
image/bmp
NEFORCE_NODISCARD string content() &&noexcept
获取右值内容
NEFORCE_NODISCARD const string & content() const &noexcept
获取左值内容
static const http_content & PNG_IMG()
image/png
HTTP操作异常
HTTP方法定义
NEFORCE_NODISCARD const string & method() const &noexcept
获取左值方法
static const http_method & CONNECT()
CONNECT方法
NEFORCE_NODISCARD http_method operator&(const http_method &rhs) const &
方法组合操作符
NEFORCE_NODISCARD string method() &&noexcept
获取右值方法
http_method & operator=(const string &method)
左值字符串赋值运算符
static const http_method & HEAD()
HEAD方法
http_method(const string &method)
左值字符串构造函数
static const http_method & PUT()
PUT方法
http_method & operator=(string &&method)
右值字符串赋值运算符
static const http_method & DELETE()
DELETE方法
static const http_method & DEFAULT()
默认方法
static const http_method & POST()
POST方法
static const http_method & OPTIONS()
OPTIONS方法
NEFORCE_NODISCARD string to_string() const
转换为字符串
static const http_method & TRACE()
TRACE方法
http_method(http_method &&other) noexcept
移动构造函数
static const http_method & PATCH()
PATCH方法
http_method & operator=(http_method &&other) noexcept
移动赋值运算符
http_method(string &&method)
右值字符串构造函数
static const http_method & GET()
GET方法
可字符串化接口