2021SC@SDUSC BRPC source code analysis (VIII) HTTP2
namespace brpc { const char *HttpReasonPhrase(int status_code); int ErrorCodeToStatusCode(int error_code); static const int HTTP_STATUS_CONTINUE = 100; static const int HTTP_STATUS_SWITCHING_PROTOCOLS = 101; static const int HTTP_STATUS_OK = 200; static const int HTTP_STATUS_CREATED = 201; static const int HTTP_STATUS_ACCEPTED = 202; static const int HTTP_STATUS_NO_CONTENT = 204; static const int HTTP_STATUS_RESET_CONTENT = 205; static const int HTTP_STATUS_PARTIAL_CONTENT = 206; static const int HTTP_STATUS_MULTIPLE_CHOICES = 300; static const int HTTP_STATUS_MOVE_PERMANENTLY = 301; static const int HTTP_STATUS_FOUND = 302; static const int HTTP_STATUS_SEE_OTHER = 303; static const int HTTP_STATUS_NOT_MODIFIED = 304; static const int HTTP_STATUS_USE_PROXY = 305; static const int HTTP_STATUS_TEMPORARY_REDIRECT = 307; static const int HTTP_STATUS_BAD_REQUEST = 400; static const int HTTP_STATUS_UNAUTHORIZED = 401; static const int HTTP_STATUS_PAYMENT_REQUIRED = 402; static const int HTTP_STATUS_FORBIDDEN = 403; static const int HTTP_STATUS_NOT_FOUND = 404; static const int HTTP_STATUS_METHOD_NOT_ALLOWED = 405; static const int HTTP_STATUS_NOT_ACCEPTABLE = 406; static const int HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED = 407; static const int HTTP_STATUS_REQUEST_TIMEOUT = 408; static const int HTTP_STATUS_CONFLICT = 409; static const int HTTP_STATUS_GONE = 410; static const int HTTP_STATUS_LENGTH_REQUIRED = 411; static const int HTTP_STATUS_PRECONDITION_FAILED = 412; static const int HTTP_STATUS_REQUEST_ENTITY_TOO_LARGE = 413; static const int HTTP_STATUS_REQUEST_URI_TOO_LARG = 414; static const int HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE = 415; static const int HTTP_STATUS_REQUEST_RANGE_NOT_SATISFIABLE = 416; static const int HTTP_STATUS_EXPECTATION_FAILED = 417; static const int HTTP_STATUS_INTERNAL_SERVER_ERROR = 500; static const int HTTP_STATUS_NOT_IMPLEMENTED = 501; static const int HTTP_STATUS_BAD_GATEWAY = 502; static const int HTTP_STATUS_SERVICE_UNAVAILABLE = 503; static const int HTTP_STATUS_GATEWAY_TIMEOUT = 504; static const int HTTP_STATUS_VERSION_NOT_SUPPORTED = 505; }
- HttpReasonPhrase returns the given status_ Code reason phrase. If status_ If the code is unknown, return Unknown status code (|status_code|) This function is thread safe and does not return NULL. The memory referenced by the previously returned pointer may be reused when the function is called again, so please do not try to cache the return value into the container. Instead, copy memory directly.
- Errorcodetostatus code converts an error code to a related status code.
- 100: continue
- 101: Exchange Protocol
- 200: OK
- 201: create
- 202: accepted
- 203: what information
- 204: no content
- 205: reset content
- 206: some contents
- 300: multiple options
- 301: permanent movement
- 302: found
- 303: see Other
- 304: not modified
- 305: using proxy
- 307: temporary redirection
- 400: bad request
- 401: unauthorized
- 402: payment required
- 403: forbidden
- 404: not found
- 405: method not allowed
- 406: unacceptable
- 407: proxy authentication required
- 408: request timed out
- 409: Conflict
- 410: disappear
- 411: length requirements
- 412: prerequisite failed
- 413: the requested entity is too large
- 414: the request URI is too large
- 415: Unsupported media type
- 416: the requested scope is not satisfied
- 417: expected failure
- 500: internal server error
- 501: not implemented
- 502: poor network
- 503: Service Unavailable
- 504: gateway timeout
- 505: HTTP version is not supported
namespace brpc { class HealthReporter { public: virtual ~HealthReporter() {} virtual void GenerateReport(Controller* cntl, google::protobuf::Closure* done) = 0; }; }
- Used to customize / health pages. Inherit this class and assign the instance to serveroptions health_ reporter.
- Get the HTTP request from cntl - > http \ u request() / cntl - > request \ u attachment(), put the response into cntl - > http \ u response() / cntl - > response \ u attachment(), and call done - > run() at the end.
#include "brpc/http_status_code.h" namespace brpc { struct H2Settings { H2Settings(); bool IsValid(bool log_error = false) const; static const uint32_t DEFAULT_HEADER_TABLE_SIZE = 4096; uint32_t header_table_size; static const bool DEFAULT_ENABLE_PUSH = true; bool enable_push; uint32_t max_concurrent_streams; static const uint32_t DEFAULT_INITIAL_WINDOW_SIZE = 65535; static const uint32_t MAX_WINDOW_SIZE = (1u << 31) - 1; uint32_t stream_window_size; uint32_t connection_window_size; static const uint32_t DEFAULT_MAX_FRAME_SIZE = 16384; static const uint32_t MAX_OF_MAX_FRAME_SIZE = 16777215; uint32_t max_frame_size; uint32_t max_header_list_size; }; std::ostream& operator<<(std::ostream& os, const H2Settings& s); enum H2Error { H2_NO_ERROR = 0x0, // Graceful shutdown H2_PROTOCOL_ERROR = 0x1, // Protocol error detected H2_INTERNAL_ERROR = 0x2, // Implementation fault H2_FLOW_CONTROL_ERROR = 0x3, // Flow-control limits exceeded H2_SETTINGS_TIMEOUT = 0x4, // Settings not acknowledged H2_STREAM_CLOSED_ERROR = 0x5, // Frame received for closed stream H2_FRAME_SIZE_ERROR = 0x6, // Frame size incorrect H2_REFUSED_STREAM = 0x7, // Stream not processed H2_CANCEL = 0x8, // Stream cancelled H2_COMPRESSION_ERROR = 0x9, // Compression state not updated H2_CONNECT_ERROR = 0xa, // TCP connection error for CONNECT method H2_ENHANCE_YOUR_CALM = 0xb, // Processing capacity exceeded H2_INADEQUATE_SECURITY = 0xc, // Negotiated TLS parameters not acceptable H2_HTTP_1_1_REQUIRED = 0xd, // Use HTTP/1.1 for the request }; const char* H2ErrorToString(H2Error e); int H2ErrorToStatusCode(H2Error e); }
-
DEFAULT_HEADER_TABLE_SIZE allows the sender to notify the remote endpoint of the maximum size (in bytes) of the header compression table used to decode the header block.
The encoder can select any size equal to or less than this value by using a signal specific to the header compression format in the header block (see [compression]). Default: 4096 -
DEFAULT_ ENABLE_ Whether push server push is enabled:
If the endpoint receives this parameter set to 0, the push commitment frame shall not be sent. Endpoints that have set this parameter to 0 and acknowledged must treat receiving push commitment frames as connection errors with typical protocol errors. Default value: false (server push is disabled). -
max_concurrent_streams the maximum number of concurrent streams allowed by the sender.
This limit is directional: it applies to the number of streams that the sender allows the receiver to create. It is recommended that this value not be less than 100 to avoid unnecessarily limiting parallelism. 0 prevents the creation of new streams. However, this can also happen for any limitation of activity flow exhaustion. The server should only set a zero value in a short time; If the server does not want to accept the request, it is more appropriate to close the connection. Default: Unlimited -
DEFAULT_INITIAL_WINDOW_SIZE the initial window size (in octets) used by the sender for flow level flow control.
This setting affects the window size of all streams. A value that exceeds the maximum flow control window size 2 ^ 31-1 is considered a connection error of the flow control error type. Default value: 256 * 1024 -
connection_window_size the initial window size controlled by the connection level flow. Default value: 1024 * 1024. Setting to zero stops printing this field.
-
DEFAULT_MAX_FRAME_SIZE the size of the maximum frame payload that the sender is willing to receive, in octets. The value published by the endpoint must be between 16384 and 16777215, inclusive. Values outside this range are considered protocol_ Wrong type of connection. Default: 16384
-
max_header_list_size this Recommendation sets the maximum size (in octets) of the header list that notifies the peer that the sender is ready to accept. The value is based on the uncompressed size of the header field, including the length of the name and value (in octets) plus the overhead of 32 octets per header field. For any given request, a lower limit than the advertisement may be enforced. Default: unlimited.
-
H2ErrorToString gets the description of the error.
-
H2ErrorToStatusCode converts an error to a status code with similar semantics