1 | #ifndef HEADER_CURL_HTTP_H |
2 | #define |
3 | /*************************************************************************** |
4 | * _ _ ____ _ |
5 | * Project ___| | | | _ \| | |
6 | * / __| | | | |_) | | |
7 | * | (__| |_| | _ <| |___ |
8 | * \___|\___/|_| \_\_____| |
9 | * |
10 | * Copyright (C) 1998 - 2021, Daniel Stenberg, <daniel@haxx.se>, et al. |
11 | * |
12 | * This software is licensed as described in the file COPYING, which |
13 | * you should have received as part of this distribution. The terms |
14 | * are also available at https://curl.se/docs/copyright.html. |
15 | * |
16 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
17 | * copies of the Software, and permit persons to whom the Software is |
18 | * furnished to do so, under the terms of the COPYING file. |
19 | * |
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
21 | * KIND, either express or implied. |
22 | * |
23 | ***************************************************************************/ |
24 | #include "curl_setup.h" |
25 | |
26 | typedef enum { |
27 | HTTPREQ_GET, |
28 | HTTPREQ_POST, |
29 | HTTPREQ_POST_FORM, /* we make a difference internally */ |
30 | HTTPREQ_POST_MIME, /* we make a difference internally */ |
31 | HTTPREQ_PUT, |
32 | HTTPREQ_HEAD |
33 | } Curl_HttpReq; |
34 | |
35 | #ifndef CURL_DISABLE_HTTP |
36 | |
37 | #ifdef USE_NGHTTP2 |
38 | #include <nghttp2/nghttp2.h> |
39 | #endif |
40 | |
41 | extern const struct Curl_handler Curl_handler_http; |
42 | |
43 | #ifdef USE_SSL |
44 | extern const struct Curl_handler Curl_handler_https; |
45 | #endif |
46 | |
47 | /* Header specific functions */ |
48 | bool (const char *, /* line to check */ |
49 | const char *, /* header keyword _with_ colon */ |
50 | const char *content); /* content string to find */ |
51 | |
52 | char *(const char *); |
53 | |
54 | char *(struct Curl_easy *data, |
55 | const struct connectdata *conn, |
56 | const char *); |
57 | #ifndef USE_HYPER |
58 | CURLcode Curl_buffer_send(struct dynbuf *in, |
59 | struct Curl_easy *data, |
60 | curl_off_t *bytes_written, |
61 | curl_off_t included_body_bytes, |
62 | int socketindex); |
63 | #else |
64 | #define Curl_buffer_send(a,b,c,d,e) CURLE_OK |
65 | #endif |
66 | |
67 | CURLcode Curl_add_timecondition(struct Curl_easy *data, |
68 | #ifndef USE_HYPER |
69 | struct dynbuf *req |
70 | #else |
71 | void *headers |
72 | #endif |
73 | ); |
74 | CURLcode (struct Curl_easy *data, |
75 | bool is_connect, |
76 | #ifndef USE_HYPER |
77 | struct dynbuf *req |
78 | #else |
79 | void *headers |
80 | #endif |
81 | ); |
82 | CURLcode Curl_http_compile_trailers(struct curl_slist *trailers, |
83 | struct dynbuf *buf, |
84 | struct Curl_easy *handle); |
85 | |
86 | void Curl_http_method(struct Curl_easy *data, struct connectdata *conn, |
87 | const char **method, Curl_HttpReq *); |
88 | CURLcode Curl_http_useragent(struct Curl_easy *data); |
89 | CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn); |
90 | CURLcode Curl_http_target(struct Curl_easy *data, struct connectdata *conn, |
91 | struct dynbuf *req); |
92 | CURLcode Curl_http_statusline(struct Curl_easy *data, |
93 | struct connectdata *conn); |
94 | CURLcode (struct Curl_easy *data, struct connectdata *conn, |
95 | char *headp); |
96 | CURLcode Curl_transferencode(struct Curl_easy *data); |
97 | CURLcode Curl_http_body(struct Curl_easy *data, struct connectdata *conn, |
98 | Curl_HttpReq httpreq, |
99 | const char **teep); |
100 | CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn, |
101 | struct dynbuf *r, Curl_HttpReq httpreq); |
102 | bool Curl_use_http_1_1plus(const struct Curl_easy *data, |
103 | const struct connectdata *conn); |
104 | #ifndef CURL_DISABLE_COOKIES |
105 | CURLcode Curl_http_cookies(struct Curl_easy *data, |
106 | struct connectdata *conn, |
107 | struct dynbuf *r); |
108 | #else |
109 | #define Curl_http_cookies(a,b,c) CURLE_OK |
110 | #endif |
111 | CURLcode Curl_http_resume(struct Curl_easy *data, |
112 | struct connectdata *conn, |
113 | Curl_HttpReq httpreq); |
114 | CURLcode Curl_http_range(struct Curl_easy *data, |
115 | Curl_HttpReq httpreq); |
116 | CURLcode Curl_http_firstwrite(struct Curl_easy *data, |
117 | struct connectdata *conn, |
118 | bool *done); |
119 | |
120 | /* protocol-specific functions set up to be called by the main engine */ |
121 | CURLcode Curl_http(struct Curl_easy *data, bool *done); |
122 | CURLcode Curl_http_done(struct Curl_easy *data, CURLcode, bool premature); |
123 | CURLcode Curl_http_connect(struct Curl_easy *data, bool *done); |
124 | |
125 | /* These functions are in http.c */ |
126 | CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy, |
127 | const char *auth); |
128 | CURLcode Curl_http_auth_act(struct Curl_easy *data); |
129 | |
130 | /* If only the PICKNONE bit is set, there has been a round-trip and we |
131 | selected to use no auth at all. Ie, we actively select no auth, as opposed |
132 | to not having one selected. The other CURLAUTH_* defines are present in the |
133 | public curl/curl.h header. */ |
134 | #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */ |
135 | |
136 | /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST |
137 | data get included in the initial data chunk sent to the server. If the |
138 | data is larger than this, it will automatically get split up in multiple |
139 | system calls. |
140 | |
141 | This value used to be fairly big (100K), but we must take into account that |
142 | if the server rejects the POST due for authentication reasons, this data |
143 | will always be unconditionally sent and thus it may not be larger than can |
144 | always be afforded to send twice. |
145 | |
146 | It must not be greater than 64K to work on VMS. |
147 | */ |
148 | #ifndef MAX_INITIAL_POST_SIZE |
149 | #define MAX_INITIAL_POST_SIZE (64*1024) |
150 | #endif |
151 | |
152 | /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will |
153 | * automatically add an "Expect: 100-continue" header in HTTP requests. When |
154 | * the size is unknown, it will always add it. |
155 | * |
156 | */ |
157 | #ifndef EXPECT_100_THRESHOLD |
158 | #define EXPECT_100_THRESHOLD (1024*1024) |
159 | #endif |
160 | |
161 | #endif /* CURL_DISABLE_HTTP */ |
162 | |
163 | #ifdef USE_NGHTTP3 |
164 | struct h3out; /* see ngtcp2 */ |
165 | #endif |
166 | |
167 | /**************************************************************************** |
168 | * HTTP unique setup |
169 | ***************************************************************************/ |
170 | struct HTTP { |
171 | curl_mimepart *sendit; |
172 | curl_off_t postsize; /* off_t to handle large file sizes */ |
173 | const char *postdata; |
174 | |
175 | const char *p_pragma; /* Pragma: string */ |
176 | |
177 | /* For FORM posting */ |
178 | curl_mimepart form; |
179 | |
180 | struct back { |
181 | curl_read_callback fread_func; /* backup storage for fread pointer */ |
182 | void *fread_in; /* backup storage for fread_in pointer */ |
183 | const char *postdata; |
184 | curl_off_t postsize; |
185 | } backup; |
186 | |
187 | enum { |
188 | HTTPSEND_NADA, /* init */ |
189 | HTTPSEND_REQUEST, /* sending a request */ |
190 | HTTPSEND_BODY /* sending body */ |
191 | } sending; |
192 | |
193 | #ifndef CURL_DISABLE_HTTP |
194 | struct dynbuf send_buffer; /* used if the request couldn't be sent in one |
195 | chunk, points to an allocated send_buffer |
196 | struct */ |
197 | #endif |
198 | #ifdef USE_NGHTTP2 |
199 | /*********** for HTTP/2 we store stream-local data here *************/ |
200 | int32_t stream_id; /* stream we are interested in */ |
201 | |
202 | bool bodystarted; |
203 | /* We store non-final and final response headers here, per-stream */ |
204 | struct dynbuf header_recvbuf; |
205 | size_t nread_header_recvbuf; /* number of bytes in header_recvbuf fed into |
206 | upper layer */ |
207 | struct dynbuf trailer_recvbuf; |
208 | int status_code; /* HTTP status code */ |
209 | const uint8_t *pausedata; /* pointer to data received in on_data_chunk */ |
210 | size_t pauselen; /* the number of bytes left in data */ |
211 | bool close_handled; /* TRUE if stream closure is handled by libcurl */ |
212 | |
213 | char **push_headers; /* allocated array */ |
214 | size_t push_headers_used; /* number of entries filled in */ |
215 | size_t push_headers_alloc; /* number of entries allocated */ |
216 | uint32_t error; /* HTTP/2 stream error code */ |
217 | #endif |
218 | #if defined(USE_NGHTTP2) || defined(USE_NGHTTP3) |
219 | bool closed; /* TRUE on HTTP2 stream close */ |
220 | char *mem; /* points to a buffer in memory to store received data */ |
221 | size_t len; /* size of the buffer 'mem' points to */ |
222 | size_t memlen; /* size of data copied to mem */ |
223 | #endif |
224 | #if defined(USE_NGHTTP2) || defined(ENABLE_QUIC) |
225 | /* fields used by both HTTP/2 and HTTP/3 */ |
226 | const uint8_t *upload_mem; /* points to a buffer to read from */ |
227 | size_t upload_len; /* size of the buffer 'upload_mem' points to */ |
228 | curl_off_t upload_left; /* number of bytes left to upload */ |
229 | #endif |
230 | |
231 | #ifdef ENABLE_QUIC |
232 | /*********** for HTTP/3 we store stream-local data here *************/ |
233 | int64_t stream3_id; /* stream we are interested in */ |
234 | bool firstheader; /* FALSE until headers arrive */ |
235 | bool firstbody; /* FALSE until body arrives */ |
236 | bool h3req; /* FALSE until request is issued */ |
237 | bool upload_done; |
238 | #endif |
239 | #ifdef USE_NGHTTP3 |
240 | size_t unacked_window; |
241 | struct h3out *h3out; /* per-stream buffers for upload */ |
242 | struct dynbuf overflow; /* excess data received during a single Curl_read */ |
243 | #endif |
244 | }; |
245 | |
246 | #ifdef USE_NGHTTP2 |
247 | /* h2 settings for this connection */ |
248 | struct h2settings { |
249 | uint32_t max_concurrent_streams; |
250 | bool enable_push; |
251 | }; |
252 | #endif |
253 | |
254 | struct http_conn { |
255 | #ifdef USE_NGHTTP2 |
256 | #define H2_BINSETTINGS_LEN 80 |
257 | uint8_t binsettings[H2_BINSETTINGS_LEN]; |
258 | size_t binlen; /* length of the binsettings data */ |
259 | |
260 | /* We associate the connnectdata struct with the connection, but we need to |
261 | make sure we can identify the current "driving" transfer. This is a |
262 | work-around for the lack of nghttp2_session_set_user_data() in older |
263 | nghttp2 versions that we want to support. (Added in 1.31.0) */ |
264 | struct Curl_easy *trnsfr; |
265 | |
266 | nghttp2_session *h2; |
267 | Curl_send *send_underlying; /* underlying send Curl_send callback */ |
268 | Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */ |
269 | char *inbuf; /* buffer to receive data from underlying socket */ |
270 | size_t inbuflen; /* number of bytes filled in inbuf */ |
271 | size_t nread_inbuf; /* number of bytes read from in inbuf */ |
272 | /* We need separate buffer for transmission and reception because we |
273 | may call nghttp2_session_send() after the |
274 | nghttp2_session_mem_recv() but mem buffer is still not full. In |
275 | this case, we wrongly sends the content of mem buffer if we share |
276 | them for both cases. */ |
277 | int32_t pause_stream_id; /* stream ID which paused |
278 | nghttp2_session_mem_recv */ |
279 | size_t drain_total; /* sum of all stream's UrlState.drain */ |
280 | |
281 | /* this is a hash of all individual streams (Curl_easy structs) */ |
282 | struct h2settings settings; |
283 | |
284 | /* list of settings that will be sent */ |
285 | nghttp2_settings_entry local_settings[3]; |
286 | size_t local_settings_num; |
287 | #else |
288 | int unused; /* prevent a compiler warning */ |
289 | #endif |
290 | }; |
291 | |
292 | CURLcode (struct Curl_easy *data, |
293 | struct connectdata *conn, |
294 | ssize_t *nread, |
295 | bool *stop_reading); |
296 | |
297 | /** |
298 | * Curl_http_output_auth() setups the authentication headers for the |
299 | * host/proxy and the correct authentication |
300 | * method. data->state.authdone is set to TRUE when authentication is |
301 | * done. |
302 | * |
303 | * @param data all information about the current transfer |
304 | * @param conn all information about the current connection |
305 | * @param request pointer to the request keyword |
306 | * @param httpreq is the request type |
307 | * @param path pointer to the requested path |
308 | * @param proxytunnel boolean if this is the request setting up a "proxy |
309 | * tunnel" |
310 | * |
311 | * @returns CURLcode |
312 | */ |
313 | CURLcode |
314 | Curl_http_output_auth(struct Curl_easy *data, |
315 | struct connectdata *conn, |
316 | const char *request, |
317 | Curl_HttpReq httpreq, |
318 | const char *path, |
319 | bool proxytunnel); /* TRUE if this is the request setting |
320 | up the proxy tunnel */ |
321 | |
322 | #endif /* HEADER_CURL_HTTP_H */ |
323 | |