NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
http_constants.hpp
浏览该文件的文档.
1#ifndef NEFORCE_NETWORK_HTTP_HTTP_CONSTANTS_HPP__
2#define NEFORCE_NETWORK_HTTP_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
185
348
349NEFORCE_API string http_status_message(http_status status);
350
351NEFORCE_API http_status http_status_from_code(uint16_t code) noexcept;
352
353
360struct NEFORCE_API http_content : istringify<http_content> {
361private:
362 string content_{"UNKNOWN"};
363
364public:
365 http_content() = default;
366 http_content(const http_content&) = default;
367 http_content& operator=(const http_content&) = default;
368
373 http_content(http_content&& other) noexcept :
374 content_(_NEFORCE move(other.content_)) {}
375
381 http_content& operator=(http_content&& other) noexcept {
382 if (addressof(other) == this) {
383 return *this;
384 }
385 content_ = _NEFORCE move(other.content_);
386 return *this;
387 }
388
393 explicit http_content(const string& content) :
394 content_(content) {}
395
401 http_content& operator=(const string& content) {
402 content_ = content;
403 return *this;
404 }
405
406 ~http_content() = default;
407
408 static const http_content& HTML_TEXT();
409 static const http_content& XML_TEXT();
410 static const http_content& CSS_TEXT();
411 static const http_content& PLAIN_TEXT();
412 static const http_content& JSON_APP();
413 static const http_content& FORM_APP();
414 static const http_content& JPEG_IMG();
415 static const http_content& PNG_IMG();
416 static const http_content& BMP_IMG();
417 static const http_content& WEBP_IMG();
418 static const http_content& HTML_MSG();
419
420 NEFORCE_NODISCARD bool is_html_text() const { return content_ == HTML_TEXT().content_; }
421 NEFORCE_NODISCARD bool is_xml_text() const { return content_ == XML_TEXT().content_; }
422 NEFORCE_NODISCARD bool is_css_text() const { return content_ == CSS_TEXT().content_; }
423 NEFORCE_NODISCARD bool is_plain_text() const { return content_ == PLAIN_TEXT().content_; }
424 NEFORCE_NODISCARD bool is_json_app() const { return content_ == JSON_APP().content_; }
425 NEFORCE_NODISCARD bool is_form_app() const { return content_ == FORM_APP().content_; }
426 NEFORCE_NODISCARD bool is_jpeg_img() const { return content_ == JPEG_IMG().content_; }
427 NEFORCE_NODISCARD bool is_png_img() const { return content_ == PNG_IMG().content_; }
428 NEFORCE_NODISCARD bool is_bmp_img() const { return content_ == BMP_IMG().content_; }
429 NEFORCE_NODISCARD bool is_webp_img() const { return content_ == WEBP_IMG().content_; }
430 NEFORCE_NODISCARD bool is_html_msg() const { return content_ == HTML_MSG().content_; }
431
432 NEFORCE_NODISCARD static bool is_html_text(const string_view view) { return view == HTML_TEXT().content_; }
433 NEFORCE_NODISCARD static bool is_xml_text(const string_view view) { return view == XML_TEXT().content_; }
434 NEFORCE_NODISCARD static bool is_css_text(const string_view view) { return view == CSS_TEXT().content_; }
435 NEFORCE_NODISCARD static bool is_plain_text(const string_view view) { return view == PLAIN_TEXT().content_; }
436 NEFORCE_NODISCARD static bool is_json_app(const string_view view) { return view == JSON_APP().content_; }
437 NEFORCE_NODISCARD static bool is_form_app(const string_view view) { return view == FORM_APP().content_; }
438 NEFORCE_NODISCARD static bool is_jpeg_img(const string_view view) { return view == JPEG_IMG().content_; }
439 NEFORCE_NODISCARD static bool is_png_img(const string_view view) { return view == PNG_IMG().content_; }
440 NEFORCE_NODISCARD static bool is_bmp_img(const string_view view) { return view == BMP_IMG().content_; }
441 NEFORCE_NODISCARD static bool is_webp_img(const string_view view) { return view == WEBP_IMG().content_; }
442 NEFORCE_NODISCARD static bool is_html_msg(const string_view view) { return view == HTML_MSG().content_; }
443
448 NEFORCE_NODISCARD const string& content() const& noexcept { return content_; }
449
454 NEFORCE_NODISCARD string content() && noexcept { return _NEFORCE move(content_); }
455
460 NEFORCE_NODISCARD string to_string() const { return content_; }
461};
462
463
464#ifdef DELETE
465# undef DELETE
466#endif
467
474struct NEFORCE_API http_method : istringify<http_method> {
475private:
476 string method_{"UNKNOWN"};
477
478public:
479 http_method() = default;
480 http_method(const http_method&) = default;
481 http_method& operator=(const http_method&) = default;
482
487 http_method(http_method&& other) noexcept :
488 method_(_NEFORCE move(other.method_)) {}
489
495 http_method& operator=(http_method&& other) noexcept {
496 if (_NEFORCE addressof(other) == this) {
497 return *this;
498 }
499 method_ = _NEFORCE move(other.method_);
500 return *this;
501 }
502
507 explicit http_method(const string& method) :
508 method_(method) {}
509
515 http_method& operator=(const string& method) {
516 method_ = method;
517 return *this;
518 }
519
524 explicit http_method(string&& method) :
525 method_(_NEFORCE move(method)) {}
526
532 http_method& operator=(string&& method) {
533 method_ = _NEFORCE move(method);
534 return *this;
535 }
536
537 ~http_method() = default;
538
539 static const http_method& GET();
540 static const http_method& POST();
541 static const http_method& HEAD();
542 static const http_method& PUT();
543 static const http_method& DELETE();
544 static const http_method& OPTIONS();
545 static const http_method& TRACE();
546 static const http_method& CONNECT();
547 static const http_method& PATCH();
548 static const http_method& DEFAULT();
549
554 NEFORCE_NODISCARD const string& method() const& noexcept { return method_; }
555
560 NEFORCE_NODISCARD string method() && noexcept { return _NEFORCE move(method_); }
561
569 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) const& {
570 return http_method(method_ + ", " + rhs.method_);
571 }
572
573 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) const& {
574 return http_method(method_ + ", " + _NEFORCE move(rhs.method_));
575 }
576
577 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) && {
578 return http_method(_NEFORCE move(method_) + ", " + rhs.method_);
579 }
580
581 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) && {
582 return http_method(_NEFORCE move(method_) + ", " + _NEFORCE move(rhs.method_));
583 }
584
585 NEFORCE_NODISCARD bool is_get() const { return method_ == GET().method_; }
586 NEFORCE_NODISCARD bool is_post() const { return method_ == POST().method_; }
587 NEFORCE_NODISCARD bool is_head() const { return method_ == HEAD().method_; }
588 NEFORCE_NODISCARD bool is_put() const { return method_ == PUT().method_; }
589 NEFORCE_NODISCARD bool is_delete() const { return method_ == DELETE().method_; }
590 NEFORCE_NODISCARD bool is_options() const { return method_ == OPTIONS().method_; }
591 NEFORCE_NODISCARD bool is_trace() const { return method_ == TRACE().method_; }
592 NEFORCE_NODISCARD bool is_connect() const { return method_ == CONNECT().method_; }
593 NEFORCE_NODISCARD bool is_patch() const { return method_ == PATCH().method_; }
594
599 NEFORCE_NODISCARD string to_string() const { return method_; }
600};
601
602
609struct NEFORCE_API http_cookie_name : istringify<http_cookie_name> {
610private:
611 string cookie_{"UNKNOWN"};
612
613public:
614 http_cookie_name() = default;
615 http_cookie_name(const http_cookie_name&) = default;
616 http_cookie_name& operator=(const http_cookie_name&) = default;
617
622 http_cookie_name(http_cookie_name&& other) noexcept :
623 cookie_(_NEFORCE move(other.cookie_)) {}
624
630 http_cookie_name& operator=(http_cookie_name&& other) noexcept {
631 if (_NEFORCE addressof(other) == this) {
632 return *this;
633 }
634 cookie_ = _NEFORCE move(other.cookie_);
635 return *this;
636 }
637
642 explicit http_cookie_name(const string& cookie) :
643 cookie_(cookie) {}
644
650 http_cookie_name& operator=(const string& cookie) {
651 cookie_ = cookie;
652 return *this;
653 }
654
655 ~http_cookie_name() = default;
656
657 static const http_cookie_name& JSESSIONID();
658 static const http_cookie_name& SESSIONID();
659 static const http_cookie_name& PHPSESSID();
660 static const http_cookie_name& ASPSESSIONID();
661
666 NEFORCE_NODISCARD const string& cookie_name() const& noexcept { return cookie_; }
667
672 NEFORCE_NODISCARD string cookie_name() && noexcept { return _NEFORCE move(cookie_); }
673
678 NEFORCE_NODISCARD string to_string() const { return cookie_; }
679};
680
681
682struct NEFORCE_API http_key {
683 static const string& Access_Control_Allow_Credentials();
684 static const string& Access_Control_Allow_Headers();
685 static const string& Access_Control_Allow_Methods();
686 static const string& Access_Control_Allow_Origin();
687 static const string& Access_Control_Max_Age();
688 static const string& Connection();
689 static const string& Content_Length();
690 static const string& Content_Type();
691 static const string& Lax();
692 static const string& Strict();
693 static const string& X_Forwarded_Proto();
694};
695 // Http
697
698NEFORCE_END_HTTP__
699NEFORCE_END_NAMESPACE__
700#endif // NEFORCE_NETWORK_HTTP_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)
构建最终异常类宏
@ 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_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 客户端请求超时
可字符串化接口
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方法
可字符串化接口