Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Utilities/cmnghttp2/lib/nghttp2_http.h
3153 views
1
/*
2
* nghttp2 - HTTP/2 C Library
3
*
4
* Copyright (c) 2015 Tatsuhiro Tsujikawa
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining
7
* a copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sublicense, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* The above copyright notice and this permission notice shall be
15
* included in all copies or substantial portions of the Software.
16
*
17
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
*/
25
#ifndef NGHTTP2_HTTP_H
26
#define NGHTTP2_HTTP_H
27
28
#ifdef HAVE_CONFIG_H
29
# include <config.h>
30
#endif /* HAVE_CONFIG_H */
31
32
#include <nghttp2/nghttp2.h>
33
#include "nghttp2_session.h"
34
#include "nghttp2_stream.h"
35
36
/*
37
* This function is called when HTTP header field |nv| in |frame| is
38
* received for |stream|. This function will validate |nv| against
39
* the current state of stream.
40
*
41
* This function returns 0 if it succeeds, or one of the following
42
* negative error codes:
43
*
44
* NGHTTP2_ERR_HTTP_HEADER
45
* Invalid HTTP header field was received.
46
* NGHTTP2_ERR_IGN_HTTP_HEADER
47
* Invalid HTTP header field was received but it can be treated as
48
* if it was not received because of compatibility reasons.
49
*/
50
int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
51
nghttp2_frame *frame, nghttp2_hd_nv *nv,
52
int trailer);
53
54
/*
55
* This function is called when request header is received. This
56
* function performs validation and returns 0 if it succeeds, or -1.
57
*/
58
int nghttp2_http_on_request_headers(nghttp2_stream *stream,
59
nghttp2_frame *frame);
60
61
/*
62
* This function is called when response header is received. This
63
* function performs validation and returns 0 if it succeeds, or -1.
64
*/
65
int nghttp2_http_on_response_headers(nghttp2_stream *stream);
66
67
/*
68
* This function is called trailer header (for both request and
69
* response) is received. This function performs validation and
70
* returns 0 if it succeeds, or -1.
71
*/
72
int nghttp2_http_on_trailer_headers(nghttp2_stream *stream,
73
nghttp2_frame *frame);
74
75
/*
76
* This function is called when END_STREAM flag is seen in incoming
77
* frame. This function performs validation and returns 0 if it
78
* succeeds, or -1.
79
*/
80
int nghttp2_http_on_remote_end_stream(nghttp2_stream *stream);
81
82
/*
83
* This function is called when chunk of data is received. This
84
* function performs validation and returns 0 if it succeeds, or -1.
85
*/
86
int nghttp2_http_on_data_chunk(nghttp2_stream *stream, size_t n);
87
88
/*
89
* This function inspects header field in |frame| and records its
90
* method in stream->http_flags. If frame->hd.type is neither
91
* NGHTTP2_HEADERS nor NGHTTP2_PUSH_PROMISE, this function does
92
* nothing.
93
*/
94
void nghttp2_http_record_request_method(nghttp2_stream *stream,
95
nghttp2_frame *frame);
96
97
/*
98
* RFC 8941 Structured Field Values.
99
*/
100
typedef enum nghttp2_sf_value_type {
101
NGHTTP2_SF_VALUE_TYPE_BOOLEAN,
102
NGHTTP2_SF_VALUE_TYPE_INTEGER,
103
NGHTTP2_SF_VALUE_TYPE_DECIMAL,
104
NGHTTP2_SF_VALUE_TYPE_STRING,
105
NGHTTP2_SF_VALUE_TYPE_TOKEN,
106
NGHTTP2_SF_VALUE_TYPE_BYTESEQ,
107
NGHTTP2_SF_VALUE_TYPE_INNER_LIST,
108
} nghttp2_sf_value_type;
109
110
/*
111
* nghttp2_sf_value stores Structured Field Values item. For Inner
112
* List, only type is set to NGHTTP2_SF_VALUE_TYPE_INNER_LIST.
113
*/
114
typedef struct nghttp2_sf_value {
115
uint8_t type;
116
union {
117
int b;
118
int64_t i;
119
double d;
120
struct {
121
const uint8_t *base;
122
size_t len;
123
} s;
124
};
125
} nghttp2_sf_value;
126
127
/*
128
* nghttp2_sf_parse_item parses the input sequence [|begin|, |end|)
129
* and stores the parsed an Item in |dest|. It returns the number of
130
* bytes consumed if it succeeds, or -1. This function is declared
131
* here for unit tests.
132
*/
133
ssize_t nghttp2_sf_parse_item(nghttp2_sf_value *dest, const uint8_t *begin,
134
const uint8_t *end);
135
136
/*
137
* nghttp2_sf_parse_inner_list parses the input sequence [|begin|, |end|)
138
* and stores the parsed an Inner List in |dest|. It returns the number of
139
* bytes consumed if it succeeds, or -1. This function is declared
140
* here for unit tests.
141
*/
142
ssize_t nghttp2_sf_parse_inner_list(nghttp2_sf_value *dest,
143
const uint8_t *begin, const uint8_t *end);
144
145
int nghttp2_http_parse_priority(nghttp2_extpri *dest, const uint8_t *value,
146
size_t valuelen);
147
148
#endif /* NGHTTP2_HTTP_H */
149
150