src/core/lib/http/parser.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2015 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #ifndef GRPC_CORE_LIB_HTTP_PARSER_H
20 #define GRPC_CORE_LIB_HTTP_PARSER_H
21 
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 
27 #include <grpc/slice.h>
28 
31 
32 /* Maximum length of a header string of the form 'Key: Value\r\n' */
33 #define GRPC_HTTP_PARSER_MAX_HEADER_LENGTH 4096
34 
35 /* A single header to be passed in a request */
36 typedef struct grpc_http_header {
37  char* key;
38  char* value;
40 
41 typedef enum {
48 
49 typedef enum {
56 
57 typedef enum {
62 
63 typedef enum {
67 
68 /* A request */
69 typedef struct grpc_http_request {
70  /* Method of the request (e.g. GET, POST) */
71  char* method;
72  /* The path of the resource to fetch (only used for parsed requests) */
73  char* path;
74  /* HTTP version to use */
76  /* Headers attached to the request */
77  size_t hdr_count;
79  /* Body: length and contents; contents are NOT null-terminated */
80  size_t body_length;
81  char* body;
83 
84 /* A response */
85 typedef struct grpc_http_response {
86  /* HTTP status code */
87  int status = 0;
88  /* Headers: count and key/values */
89  size_t hdr_count = 0;
90  grpc_http_header* hdrs = nullptr;
91  /* Body: length and contents; contents are NOT null-terminated */
92  size_t body_length = 0;
93  /* State of the chunked parser. Only valid for the response. */
95  size_t chunk_length = 0;
96  char* body = nullptr;
98 
102 
103  union {
107  } http;
109  size_t hdr_capacity;
110 
114 };
116  void* request_or_response);
118 
119 /* Sets \a start_of_body to the offset in \a slice of the start of the body. */
121  const grpc_slice& slice,
122  size_t* start_of_body);
124 
127 
129 
130 #endif /* GRPC_CORE_LIB_HTTP_PARSER_H */
trace.h
grpc_http_request::version
grpc_http_version version
Definition: src/core/lib/http/parser.h:75
grpc_http_response::chunk_length
size_t chunk_length
Definition: src/core/lib/http/parser.h:95
grpc_http_response::chunked_state
grpc_http_parser_chunked_state chunked_state
Definition: src/core/lib/http/parser.h:94
GRPC_HTTP_CHUNKED_BODY
@ GRPC_HTTP_CHUNKED_BODY
Definition: src/core/lib/http/parser.h:53
grpc_http_parser::hdr_capacity
size_t hdr_capacity
Definition: src/core/lib/http/parser.h:109
slice.h
grpc_http_response::body
char * body
Definition: src/core/lib/http/parser.h:96
grpc_http_version
grpc_http_version
Definition: src/core/lib/http/parser.h:57
GRPC_HTTP_CHUNKED_PLAIN
@ GRPC_HTTP_CHUNKED_PLAIN
Definition: src/core/lib/http/parser.h:50
benchmark.request
request
Definition: benchmark.py:77
GRPC_HTTP_CHUNKED_LENGTH
@ GRPC_HTTP_CHUNKED_LENGTH
Definition: src/core/lib/http/parser.h:51
grpc_http_request::method
char * method
Definition: src/core/lib/http/parser.h:71
GRPC_HTTP_HEADERS
@ GRPC_HTTP_HEADERS
Definition: src/core/lib/http/parser.h:43
GRPC_HTTP_HTTP20
@ GRPC_HTTP_HTTP20
Definition: src/core/lib/http/parser.h:60
grpc_http_parser_state
grpc_http_parser_state
Definition: src/core/lib/http/parser.h:41
grpc_http_response_destroy
void grpc_http_response_destroy(grpc_http_response *response)
Definition: src/core/lib/http/parser.cc:434
grpc_http_parser_init
void grpc_http_parser_init(grpc_http_parser *parser, grpc_http_type type, void *request_or_response)
Definition: src/core/lib/http/parser.cc:411
grpc_http_parser::cur_line
uint8_t cur_line[GRPC_HTTP_PARSER_MAX_HEADER_LENGTH]
Definition: src/core/lib/http/parser.h:111
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
grpc_http_parser::request_or_response
void * request_or_response
Definition: src/core/lib/http/parser.h:106
GRPC_HTTP_FIRST_LINE
@ GRPC_HTTP_FIRST_LINE
Definition: src/core/lib/http/parser.h:42
GRPC_HTTP_CHUNKED_CONSUME_LF
@ GRPC_HTTP_CHUNKED_CONSUME_LF
Definition: src/core/lib/http/parser.h:54
grpc_http_parser::state
grpc_http_parser_state state
Definition: src/core/lib/http/parser.h:100
GRPC_HTTP_TRAILERS
@ GRPC_HTTP_TRAILERS
Definition: src/core/lib/http/parser.h:45
grpc_http_response
Definition: src/core/lib/http/parser.h:85
grpc_http_request
struct grpc_http_request grpc_http_request
asyncio_get_stats.parser
parser
Definition: asyncio_get_stats.py:34
grpc_http_header::key
char * key
Definition: src/core/lib/http/parser.h:37
GRPC_HTTP_HTTP10
@ GRPC_HTTP_HTTP10
Definition: src/core/lib/http/parser.h:58
grpc_http_header
Definition: src/core/lib/http/parser.h:36
grpc_http_request::body
char * body
Definition: src/core/lib/http/parser.h:81
slice
grpc_slice slice
Definition: src/core/lib/surface/server.cc:467
grpc_http_parser_parse
grpc_error_handle grpc_http_parser_parse(grpc_http_parser *parser, const grpc_slice &slice, size_t *start_of_body)
Definition: src/core/lib/http/parser.cc:444
grpc_http_parser::cur_line_length
size_t cur_line_length
Definition: src/core/lib/http/parser.h:112
grpc_http_parser::response
grpc_http_response * response
Definition: src/core/lib/http/parser.h:104
grpc_http_parser::body_capacity
size_t body_capacity
Definition: src/core/lib/http/parser.h:108
grpc_http_request_destroy
void grpc_http_request_destroy(grpc_http_request *request)
Definition: src/core/lib/http/parser.cc:422
GRPC_HTTP_REQUEST
@ GRPC_HTTP_REQUEST
Definition: src/core/lib/http/parser.h:65
grpc_slice
Definition: include/grpc/impl/codegen/slice.h:65
grpc_http_parser_eof
grpc_error_handle grpc_http_parser_eof(grpc_http_parser *parser)
Definition: src/core/lib/http/parser.cc:457
error.h
grpc_http_parser_destroy
void grpc_http_parser_destroy(grpc_http_parser *parser)
Definition: src/core/lib/http/parser.cc:420
grpc_http_parser_chunked_state
grpc_http_parser_chunked_state
Definition: src/core/lib/http/parser.h:49
grpc_http_response::hdrs
grpc_http_header * hdrs
Definition: src/core/lib/http/parser.h:90
stdint.h
grpc_http1_trace
grpc_core::TraceFlag grpc_http1_trace
GRPC_HTTP_BODY
@ GRPC_HTTP_BODY
Definition: src/core/lib/http/parser.h:44
grpc_http_response::status
int status
Definition: src/core/lib/http/parser.h:87
grpc_http_parser::type
grpc_http_type type
Definition: src/core/lib/http/parser.h:101
grpc_core::TraceFlag
Definition: debug/trace.h:63
grpc_http_header
struct grpc_http_header grpc_http_header
grpc_http_request::hdr_count
size_t hdr_count
Definition: src/core/lib/http/parser.h:77
grpc_http_response::body_length
size_t body_length
Definition: src/core/lib/http/parser.h:92
GRPC_HTTP_CHUNKED_IGNORE_ALL_UNTIL_LF
@ GRPC_HTTP_CHUNKED_IGNORE_ALL_UNTIL_LF
Definition: src/core/lib/http/parser.h:52
asyncio_get_stats.response
response
Definition: asyncio_get_stats.py:28
grpc_http_header::value
char * value
Definition: src/core/lib/http/parser.h:38
GRPC_HTTP_PARSER_MAX_HEADER_LENGTH
#define GRPC_HTTP_PARSER_MAX_HEADER_LENGTH
Definition: src/core/lib/http/parser.h:33
grpc_http_request::body_length
size_t body_length
Definition: src/core/lib/http/parser.h:80
grpc_http_response
struct grpc_http_response grpc_http_response
GRPC_HTTP_END
@ GRPC_HTTP_END
Definition: src/core/lib/http/parser.h:46
grpc_http_request::path
char * path
Definition: src/core/lib/http/parser.h:73
grpc_http_response::hdr_count
size_t hdr_count
Definition: src/core/lib/http/parser.h:89
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
GRPC_HTTP_RESPONSE
@ GRPC_HTTP_RESPONSE
Definition: src/core/lib/http/parser.h:64
grpc_http_request::hdrs
grpc_http_header * hdrs
Definition: src/core/lib/http/parser.h:78
GRPC_HTTP_HTTP11
@ GRPC_HTTP_HTTP11
Definition: src/core/lib/http/parser.h:59
grpc_error
Definition: error_internal.h:42
grpc_http_parser::request
grpc_http_request * request
Definition: src/core/lib/http/parser.h:105
grpc_http_parser
Definition: src/core/lib/http/parser.h:99
grpc_http_type
grpc_http_type
Definition: src/core/lib/http/parser.h:63
grpc_http_parser::http
union grpc_http_parser::@13 http
grpc_http_request
Definition: src/core/lib/http/parser.h:69
grpc_http_parser::cur_line_end_length
size_t cur_line_end_length
Definition: src/core/lib/http/parser.h:113
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:40