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
440
441NEFORCE_API string http_status_message(http_status status);
442
443NEFORCE_API http_status http_status_from_code(uint16_t code) noexcept;
444
445
452struct NEFORCE_API http_content : istringify<http_content> {
453private:
454 string content_{"UNKNOWN"};
455
456public:
457 http_content() = default;
458 http_content(const http_content&) = default;
459 http_content& operator=(const http_content&) = default;
460
465 http_content(http_content&& other) noexcept :
466 content_(_NEFORCE move(other.content_)) {}
467
473 http_content& operator=(http_content&& other) noexcept {
474 if (addressof(other) == this) {
475 return *this;
476 }
477 content_ = _NEFORCE move(other.content_);
478 return *this;
479 }
480
485 explicit http_content(string content) :
486 content_(move(content)) {}
487
493 http_content& operator=(const string& content) {
494 content_ = content;
495 return *this;
496 }
497
498 ~http_content() = default;
499
500 static const http_content& HTML_TEXT();
501 static const http_content& XML_TEXT();
502 static const http_content& CSS_TEXT();
503 static const http_content& PLAIN_TEXT();
504 static const http_content& JSON_APP();
505 static const http_content& FORM_APP();
506 static const http_content& JPEG_IMG();
507 static const http_content& PNG_IMG();
508 static const http_content& BMP_IMG();
509 static const http_content& WEBP_IMG();
510 static const http_content& HTML_MSG();
511
512 NEFORCE_NODISCARD bool is_html_text() const { return content_ == HTML_TEXT().content_; }
513 NEFORCE_NODISCARD bool is_xml_text() const { return content_ == XML_TEXT().content_; }
514 NEFORCE_NODISCARD bool is_css_text() const { return content_ == CSS_TEXT().content_; }
515 NEFORCE_NODISCARD bool is_plain_text() const { return content_ == PLAIN_TEXT().content_; }
516 NEFORCE_NODISCARD bool is_json_app() const { return content_ == JSON_APP().content_; }
517 NEFORCE_NODISCARD bool is_form_app() const { return content_ == FORM_APP().content_; }
518 NEFORCE_NODISCARD bool is_jpeg_img() const { return content_ == JPEG_IMG().content_; }
519 NEFORCE_NODISCARD bool is_png_img() const { return content_ == PNG_IMG().content_; }
520 NEFORCE_NODISCARD bool is_bmp_img() const { return content_ == BMP_IMG().content_; }
521 NEFORCE_NODISCARD bool is_webp_img() const { return content_ == WEBP_IMG().content_; }
522 NEFORCE_NODISCARD bool is_html_msg() const { return content_ == HTML_MSG().content_; }
523
524 NEFORCE_NODISCARD static bool is_html_text(const string_view view) { return view == HTML_TEXT().content_; }
525 NEFORCE_NODISCARD static bool is_xml_text(const string_view view) { return view == XML_TEXT().content_; }
526 NEFORCE_NODISCARD static bool is_css_text(const string_view view) { return view == CSS_TEXT().content_; }
527 NEFORCE_NODISCARD static bool is_plain_text(const string_view view) { return view == PLAIN_TEXT().content_; }
528 NEFORCE_NODISCARD static bool is_json_app(const string_view view) { return view == JSON_APP().content_; }
529 NEFORCE_NODISCARD static bool is_form_app(const string_view view) { return view == FORM_APP().content_; }
530 NEFORCE_NODISCARD static bool is_jpeg_img(const string_view view) { return view == JPEG_IMG().content_; }
531 NEFORCE_NODISCARD static bool is_png_img(const string_view view) { return view == PNG_IMG().content_; }
532 NEFORCE_NODISCARD static bool is_bmp_img(const string_view view) { return view == BMP_IMG().content_; }
533 NEFORCE_NODISCARD static bool is_webp_img(const string_view view) { return view == WEBP_IMG().content_; }
534 NEFORCE_NODISCARD static bool is_html_msg(const string_view view) { return view == HTML_MSG().content_; }
535
540 NEFORCE_NODISCARD const string& content() const& noexcept { return content_; }
541
546 NEFORCE_NODISCARD string content() && noexcept { return _NEFORCE move(content_); }
547
552 NEFORCE_NODISCARD string to_string() const { return content_; }
553};
554
555
556#ifdef DELETE
557# undef DELETE
558#endif
559
566struct NEFORCE_API http_method : istringify<http_method> {
567private:
568 string method_{"UNKNOWN"};
569
570public:
571 http_method() = default;
572 http_method(const http_method&) = default;
573 http_method& operator=(const http_method&) = default;
574
579 http_method(http_method&& other) noexcept :
580 method_(_NEFORCE move(other.method_)) {}
581
587 http_method& operator=(http_method&& other) noexcept {
588 if (_NEFORCE addressof(other) == this) {
589 return *this;
590 }
591 method_ = _NEFORCE move(other.method_);
592 return *this;
593 }
594
599 explicit http_method(const string& method) :
600 method_(method) {}
601
607 http_method& operator=(const string& method) {
608 method_ = method;
609 return *this;
610 }
611
616 explicit http_method(string&& method) :
617 method_(_NEFORCE move(method)) {}
618
624 http_method& operator=(string&& method) {
625 method_ = _NEFORCE move(method);
626 return *this;
627 }
628
629 ~http_method() = default;
630
631 static const http_method& GET();
632 static const http_method& POST();
633 static const http_method& HEAD();
634 static const http_method& PUT();
635 static const http_method& DELETE();
636 static const http_method& OPTIONS();
637 static const http_method& TRACE();
638 static const http_method& CONNECT();
639 static const http_method& PATCH();
640 static const http_method& DEFAULT();
641
646 NEFORCE_NODISCARD const string& method() const& noexcept { return method_; }
647
652 NEFORCE_NODISCARD string method() && noexcept { return _NEFORCE move(method_); }
653
661 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) const& {
662 return http_method(method_ + ", " + rhs.method_);
663 }
664
665 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) const& {
666 return http_method(method_ + ", " + _NEFORCE move(rhs.method_));
667 }
668
669 NEFORCE_NODISCARD http_method operator&(const http_method& rhs) && {
670 return http_method(_NEFORCE move(method_) + ", " + rhs.method_);
671 }
672
673 NEFORCE_NODISCARD http_method operator&(http_method&& rhs) && {
674 return http_method(_NEFORCE move(method_) + ", " + _NEFORCE move(rhs.method_));
675 }
676
677 NEFORCE_NODISCARD bool is_get() const { return method_ == GET().method_; }
678 NEFORCE_NODISCARD bool is_post() const { return method_ == POST().method_; }
679 NEFORCE_NODISCARD bool is_head() const { return method_ == HEAD().method_; }
680 NEFORCE_NODISCARD bool is_put() const { return method_ == PUT().method_; }
681 NEFORCE_NODISCARD bool is_delete() const { return method_ == DELETE().method_; }
682 NEFORCE_NODISCARD bool is_options() const { return method_ == OPTIONS().method_; }
683 NEFORCE_NODISCARD bool is_trace() const { return method_ == TRACE().method_; }
684 NEFORCE_NODISCARD bool is_connect() const { return method_ == CONNECT().method_; }
685 NEFORCE_NODISCARD bool is_patch() const { return method_ == PATCH().method_; }
686
691 NEFORCE_NODISCARD string to_string() const { return method_; }
692};
693
694
701struct NEFORCE_API http_cookie_name : istringify<http_cookie_name> {
702private:
703 string cookie_{"UNKNOWN"};
704
705public:
706 http_cookie_name() = default;
707 http_cookie_name(const http_cookie_name&) = default;
708 http_cookie_name& operator=(const http_cookie_name&) = default;
709
714 http_cookie_name(http_cookie_name&& other) noexcept :
715 cookie_(_NEFORCE move(other.cookie_)) {}
716
722 http_cookie_name& operator=(http_cookie_name&& other) noexcept {
723 if (_NEFORCE addressof(other) == this) {
724 return *this;
725 }
726 cookie_ = _NEFORCE move(other.cookie_);
727 return *this;
728 }
729
734 explicit http_cookie_name(string cookie) :
735 cookie_(move(cookie)) {}
736
742 http_cookie_name& operator=(const string& cookie) {
743 cookie_ = cookie;
744 return *this;
745 }
746
747 ~http_cookie_name() = default;
748
749 static const http_cookie_name& JSESSIONID();
750 static const http_cookie_name& SESSIONID();
751 static const http_cookie_name& PHPSESSID();
752 static const http_cookie_name& ASPSESSIONID();
753
758 NEFORCE_NODISCARD const string& cookie_name() const& noexcept { return cookie_; }
759
764 NEFORCE_NODISCARD string cookie_name() && noexcept { return _NEFORCE move(cookie_); }
765
770 NEFORCE_NODISCARD string to_string() const { return cookie_; }
771};
772
773
774struct NEFORCE_API http_key {
775 static const string& Access_Control_Allow_Credentials();
776 static const string& Access_Control_Allow_Headers();
777 static const string& Access_Control_Allow_Methods();
778 static const string& Access_Control_Allow_Origin();
779 static const string& Access_Control_Max_Age();
780 static const string& Connection();
781 static const string& Content_Length();
782 static const string& Content_Type();
783 static const string& Lax();
784 static const string& Strict();
785 static const string& X_Forwarded_Proto();
786};
787 // Http
789
790NEFORCE_END_HTTP__
791NEFORCE_END_NAMESPACE__
792#endif // NEFORCE_NETWORK_HTTP_HTTP_CONSTANTS_HPP__
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_HTTP_VERSION_NOT_SUPPORTED
505 HTTP Version Not Supported 不支持的HTTP版本
@ S5_GATEWAY_TIMEOUT
504 Gateway Timeout 上游服务器响应超时
@ S5_BAD_GATEWAY
502 Bad Gateway 上游服务器响应无效
@ S5_INTERNAL_SERVER_ERROR
500 Internal Server Error 服务器内部错误
@ S1_SWITCHING_PROTOCOLS
101 Switching Protocols 同意切换协议
@ S4_UNAUTHORIZED
401 Unauthorized 需要身份验证
@ S4_METHOD_NOT_ALLOWED
405 Method Not Allowed 请求方法不允许
@ S4_FORBIDDEN
403 Forbidden 服务器拒绝请求
@ S4_UNAVAILABLE_FOR_LEGAL_REASONS
451 Unavailable For Legal Reasons 因法律原因不可用
@ S1_CONTINUE
100 Continue 服务器收到请求头,客户端可以继续发送请求体
@ S4_EXPECTATION_FAILED
417 Expectation Failed 无法满足Expect请求头
@ S3_NOT_MODIFIED
304 Not Modified 资源未修改,可使用本地缓存
@ S2_CREATED
201 Created 请求成功并创建了新资源
@ S4_URI_TOO_LONG
414 URI Too Long 请求URL过长
@ S4_UNSUPPORTED_MEDIA_TYPE
415 Unsupported Media Type 不支持的媒体格式
@ S5_NOT_IMPLEMENTED
501 Not Implemented 服务器不支持该请求功能
@ S2_PARTIAL_CONTENT
206 Partial Content 部分请求成功(范围请求)
@ S3_MOVED_PERMANENT
301 Moved Permanently 资源已永久迁移到新URL
@ S4_CONFLICT
409 Conflict 请求与资源当前状态冲突
@ S4_TOO_MANY_REQUESTS
429 Too Many Requests 请求次数过多
@ S4_LENGTH_REQUIRED
411 Length Required 请求未指定Content-Length
@ S4_PRECONDITION_FAILED
412 Precondition Failed 请求先决条件未满足
@ S5_SERVICE_UNAVAILABLE
503 Service Unavailable 服务暂时不可用
@ S2_NO_CONTENT
204 No Content 请求成功但无内容返回
@ S4_UNPROCESSABLE_CONTENT
422 Unprocessable Content 请求格式正确但语义有误
@ S4_UPGRADE_REQUIRED
426 Upgrade Required 需要升级协议
@ S4_HEADER_FIELDS_TOO_LARGE
431 Request Header Fields Too Large 请求头字段过大
@ S2_OK
200 OK 请求成功
@ S3_FOUND
302 Found 资源临时迁移到新URL
@ S4_NOT_FOUND
404 Not Found 请求的资源不存在
@ S2_ACCEPTED
202 Accepted 请求已接受但尚未处理
@ S4_RANGE_NOT_SATISFIABLE
416 Range Not Satisfiable 无法满足Range请求
@ S4_PAYLOAD_TOO_LARGE
413 Payload Too Large 请求体过大
@ S4_BAD_REQUEST
400 Bad Request 请求格式错误
@ S3_TEMPORARY_REDIRECT
307 Temporary Redirect 临时重定向
@ S4_PROXY_AUTH_REQUIRED
407 Proxy Authentication Required 需要通过代理认证
@ S3_PERMANENT_REDIRECT
308 Permanent Redirect 永久重定向
@ S4_NOT_ACCEPTABLE
406 Not Acceptable 无法生成匹配Accept头的内容
@ S4_GONE
410 Gone 资源已永久删除
@ S4_REQUEST_TIMEOUT
408 Request Timeout 客户端请求超时
@ S3_SEE_OTHER
303 See Other 重定向到另一个URI获取响应
可字符串化接口
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
string to_string() const
转换为字符串
static const http_content & JSON_APP()
application/json
static const http_content & JPEG_IMG()
image/jpeg
http_content(string content)
字符串构造函数
http_content(http_content &&other) noexcept
移动构造函数
const string & content() const &noexcept
获取左值内容
static const http_content & HTML_MSG()
message/html
string content() &&noexcept
获取右值内容
static const http_content & HTML_TEXT()
text/html
http_content & operator=(const string &content)
字符串赋值运算符
static const http_content & WEBP_IMG()
image/webp
static const http_content & CSS_TEXT()
text/css
static const http_content & BMP_IMG()
image/bmp
static const http_content & PNG_IMG()
image/png
HTTP操作异常
HTTP方法定义
static const http_method & CONNECT()
CONNECT方法
http_method & operator=(const string &method)
左值字符串赋值运算符
static const http_method & HEAD()
HEAD方法
string to_string() const
转换为字符串
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()
默认方法
http_method operator&(const http_method &rhs) const &
方法组合操作符
static const http_method & POST()
POST方法
const string & method() const &noexcept
获取左值方法
static const http_method & OPTIONS()
OPTIONS方法
static const http_method & TRACE()
TRACE方法
string method() &&noexcept
获取右值方法
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方法
可字符串化接口