GRPC C++  1.26.0
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 <grpc/slice.h>
27 
28 /* Maximum length of a header string of the form 'Key: Value\r\n' */
29 #define GRPC_HTTP_PARSER_MAX_HEADER_LENGTH 4096
30 
31 /* A single header to be passed in a request */
32 typedef struct grpc_http_header {
33  char* key;
34  char* value;
36 
37 typedef enum {
42 
43 typedef enum {
48 
49 typedef enum {
53 
54 /* A request */
55 typedef struct grpc_http_request {
56  /* Method of the request (e.g. GET, POST) */
57  char* method;
58  /* The path of the resource to fetch */
59  char* path;
60  /* HTTP version to use */
62  /* Headers attached to the request */
63  size_t hdr_count;
65  /* Body: length and contents; contents are NOT null-terminated */
66  size_t body_length;
67  char* body;
69 
70 /* A response */
71 typedef struct grpc_http_response {
72  /* HTTP status code */
73  int status = 0;
74  /* Headers: count and key/values */
75  size_t hdr_count = 0;
76  grpc_http_header* hdrs = nullptr;
77  /* Body: length and contents; contents are NOT null-terminated */
78  size_t body_length = 0;
79  char* body = nullptr;
81 
82 typedef struct {
85 
86  union {
90  } http;
91  size_t body_capacity;
92  size_t hdr_capacity;
93 
98 
100  void* request_or_response);
102 
103 /* Sets \a start_of_body to the offset in \a slice of the start of the body. */
105  const grpc_slice& slice,
106  size_t* start_of_body);
108 
111 
113 
114 #endif /* GRPC_CORE_LIB_HTTP_PARSER_H */
Definition: parser.h:40
grpc_core::TraceFlag grpc_http1_trace
void * request_or_response
Definition: parser.h:89
char * body
Definition: parser.h:79
struct grpc_http_request grpc_http_request
Definition: parser.h:55
void grpc_http_request_destroy(grpc_http_request *request)
Definition: parser.h:82
size_t cur_line_length
Definition: parser.h:95
grpc_http_header * hdrs
Definition: parser.h:64
Definition: parser.h:71
grpc_http_version version
Definition: parser.h:61
size_t body_length
Definition: parser.h:78
A grpc_slice s, if initialized, represents the byte range s.bytes[0..s.length-1]. ...
Definition: slice.h:60
Definition: parser.h:46
Definition: parser.h:32
Definition: error_internal.h:39
Definition: parser.h:51
char * value
Definition: parser.h:34
Definition: parser.h:38
size_t body_capacity
Definition: parser.h:91
grpc_http_parser_state state
Definition: parser.h:83
Definition: parser.h:44
void grpc_http_parser_destroy(grpc_http_parser *parser)
size_t cur_line_end_length
Definition: parser.h:96
grpc_http_response * response
Definition: parser.h:87
Definition: trace.h:61
grpc_http_parser_state
Definition: parser.h:37
struct grpc_http_response grpc_http_response
char * path
Definition: parser.h:59
grpc_http_request * request
Definition: parser.h:88
void grpc_http_parser_init(grpc_http_parser *parser, grpc_http_type type, void *request_or_response)
grpc_http_header * hdrs
Definition: parser.h:76
size_t body_length
Definition: parser.h:66
grpc_error * grpc_http_parser_eof(grpc_http_parser *parser)
size_t hdr_count
Definition: parser.h:63
void grpc_http_response_destroy(grpc_http_response *response)
int status
Definition: parser.h:73
grpc_http_type
Definition: parser.h:49
char * body
Definition: parser.h:67
Definition: parser.h:39
struct grpc_http_header grpc_http_header
grpc_http_type type
Definition: parser.h:84
Definition: parser.h:45
grpc_http_version
Definition: parser.h:43
char * method
Definition: parser.h:57
#define GRPC_HTTP_PARSER_MAX_HEADER_LENGTH
Definition: parser.h:29
size_t hdr_capacity
Definition: parser.h:92
Definition: parser.h:50
size_t hdr_count
Definition: parser.h:75
grpc_error * grpc_http_parser_parse(grpc_http_parser *parser, const grpc_slice &slice, size_t *start_of_body)
char * key
Definition: parser.h:33