1 | #ifndef HEADER_CURL_HTTP_H
|
---|
2 | #define HEADER_CURL_HTTP_H
|
---|
3 | /***************************************************************************
|
---|
4 | * _ _ ____ _
|
---|
5 | * Project ___| | | | _ \| |
|
---|
6 | * / __| | | | |_) | |
|
---|
7 | * | (__| |_| | _ <| |___
|
---|
8 | * \___|\___/|_| \_\_____|
|
---|
9 | *
|
---|
10 | * Copyright (C) Daniel Stenberg, <[email protected]>, 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 | * SPDX-License-Identifier: curl
|
---|
24 | *
|
---|
25 | ***************************************************************************/
|
---|
26 | #include "curl_setup.h"
|
---|
27 |
|
---|
28 | #if defined(USE_MSH3) && !defined(_WIN32)
|
---|
29 | #include <pthread.h>
|
---|
30 | #endif
|
---|
31 |
|
---|
32 | #include "bufq.h"
|
---|
33 | #include "dynhds.h"
|
---|
34 | #include "ws.h"
|
---|
35 |
|
---|
36 | typedef enum {
|
---|
37 | HTTPREQ_GET,
|
---|
38 | HTTPREQ_POST,
|
---|
39 | HTTPREQ_POST_FORM, /* we make a difference internally */
|
---|
40 | HTTPREQ_POST_MIME, /* we make a difference internally */
|
---|
41 | HTTPREQ_PUT,
|
---|
42 | HTTPREQ_HEAD
|
---|
43 | } Curl_HttpReq;
|
---|
44 |
|
---|
45 | #ifndef CURL_DISABLE_HTTP
|
---|
46 |
|
---|
47 | #if defined(ENABLE_QUIC)
|
---|
48 | #include <stdint.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | extern const struct Curl_handler Curl_handler_http;
|
---|
52 |
|
---|
53 | #ifdef USE_SSL
|
---|
54 | extern const struct Curl_handler Curl_handler_https;
|
---|
55 | #endif
|
---|
56 |
|
---|
57 | struct dynhds;
|
---|
58 |
|
---|
59 | CURLcode Curl_bump_headersize(struct Curl_easy *data,
|
---|
60 | size_t delta,
|
---|
61 | bool connect_only);
|
---|
62 |
|
---|
63 | /* Header specific functions */
|
---|
64 | bool Curl_compareheader(const char *headerline, /* line to check */
|
---|
65 | const char *header, /* header keyword _with_ colon */
|
---|
66 | const size_t hlen, /* len of the keyword in bytes */
|
---|
67 | const char *content, /* content string to find */
|
---|
68 | const size_t clen); /* len of the content in bytes */
|
---|
69 |
|
---|
70 | char *Curl_copy_header_value(const char *header);
|
---|
71 |
|
---|
72 | char *Curl_checkProxyheaders(struct Curl_easy *data,
|
---|
73 | const struct connectdata *conn,
|
---|
74 | const char *thisheader,
|
---|
75 | const size_t thislen);
|
---|
76 | struct HTTP; /* see below */
|
---|
77 |
|
---|
78 | CURLcode Curl_add_timecondition(struct Curl_easy *data,
|
---|
79 | #ifndef USE_HYPER
|
---|
80 | struct dynbuf *req
|
---|
81 | #else
|
---|
82 | void *headers
|
---|
83 | #endif
|
---|
84 | );
|
---|
85 | CURLcode Curl_add_custom_headers(struct Curl_easy *data,
|
---|
86 | bool is_connect,
|
---|
87 | #ifndef USE_HYPER
|
---|
88 | struct dynbuf *req
|
---|
89 | #else
|
---|
90 | void *headers
|
---|
91 | #endif
|
---|
92 | );
|
---|
93 | CURLcode Curl_dynhds_add_custom(struct Curl_easy *data,
|
---|
94 | bool is_connect,
|
---|
95 | struct dynhds *hds);
|
---|
96 |
|
---|
97 | void Curl_http_method(struct Curl_easy *data, struct connectdata *conn,
|
---|
98 | const char **method, Curl_HttpReq *);
|
---|
99 | CURLcode Curl_http_useragent(struct Curl_easy *data);
|
---|
100 | CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn);
|
---|
101 | CURLcode Curl_http_target(struct Curl_easy *data, struct connectdata *conn,
|
---|
102 | struct dynbuf *req);
|
---|
103 | CURLcode Curl_http_statusline(struct Curl_easy *data,
|
---|
104 | struct connectdata *conn);
|
---|
105 | CURLcode Curl_http_header(struct Curl_easy *data, struct connectdata *conn,
|
---|
106 | char *headp, size_t hdlen);
|
---|
107 | CURLcode Curl_transferencode(struct Curl_easy *data);
|
---|
108 | CURLcode Curl_http_req_set_reader(struct Curl_easy *data,
|
---|
109 | Curl_HttpReq httpreq,
|
---|
110 | const char **tep);
|
---|
111 | CURLcode Curl_http_req_complete(struct Curl_easy *data,
|
---|
112 | struct dynbuf *r, Curl_HttpReq httpreq);
|
---|
113 | bool Curl_use_http_1_1plus(const struct Curl_easy *data,
|
---|
114 | const struct connectdata *conn);
|
---|
115 | #ifndef CURL_DISABLE_COOKIES
|
---|
116 | CURLcode Curl_http_cookies(struct Curl_easy *data,
|
---|
117 | struct connectdata *conn,
|
---|
118 | struct dynbuf *r);
|
---|
119 | #else
|
---|
120 | #define Curl_http_cookies(a,b,c) CURLE_OK
|
---|
121 | #endif
|
---|
122 | CURLcode Curl_http_range(struct Curl_easy *data,
|
---|
123 | Curl_HttpReq httpreq);
|
---|
124 | CURLcode Curl_http_firstwrite(struct Curl_easy *data);
|
---|
125 |
|
---|
126 | /* protocol-specific functions set up to be called by the main engine */
|
---|
127 | CURLcode Curl_http_setup_conn(struct Curl_easy *data,
|
---|
128 | struct connectdata *conn);
|
---|
129 | CURLcode Curl_http(struct Curl_easy *data, bool *done);
|
---|
130 | CURLcode Curl_http_done(struct Curl_easy *data, CURLcode, bool premature);
|
---|
131 | CURLcode Curl_http_connect(struct Curl_easy *data, bool *done);
|
---|
132 | int Curl_http_getsock_do(struct Curl_easy *data, struct connectdata *conn,
|
---|
133 | curl_socket_t *socks);
|
---|
134 | CURLcode Curl_http_write_resp(struct Curl_easy *data,
|
---|
135 | const char *buf, size_t blen,
|
---|
136 | bool is_eos);
|
---|
137 |
|
---|
138 | /* These functions are in http.c */
|
---|
139 | CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy,
|
---|
140 | const char *auth);
|
---|
141 | CURLcode Curl_http_auth_act(struct Curl_easy *data);
|
---|
142 |
|
---|
143 | /* If only the PICKNONE bit is set, there has been a round-trip and we
|
---|
144 | selected to use no auth at all. Ie, we actively select no auth, as opposed
|
---|
145 | to not having one selected. The other CURLAUTH_* defines are present in the
|
---|
146 | public curl/curl.h header. */
|
---|
147 | #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
|
---|
148 |
|
---|
149 | /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
|
---|
150 | data get included in the initial data chunk sent to the server. If the
|
---|
151 | data is larger than this, it will automatically get split up in multiple
|
---|
152 | system calls.
|
---|
153 |
|
---|
154 | This value used to be fairly big (100K), but we must take into account that
|
---|
155 | if the server rejects the POST due for authentication reasons, this data
|
---|
156 | will always be unconditionally sent and thus it may not be larger than can
|
---|
157 | always be afforded to send twice.
|
---|
158 |
|
---|
159 | It must not be greater than 64K to work on VMS.
|
---|
160 | */
|
---|
161 | #ifndef MAX_INITIAL_POST_SIZE
|
---|
162 | #define MAX_INITIAL_POST_SIZE (64*1024)
|
---|
163 | #endif
|
---|
164 |
|
---|
165 | /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will
|
---|
166 | * automatically add an "Expect: 100-continue" header in HTTP requests. When
|
---|
167 | * the size is unknown, it will always add it.
|
---|
168 | *
|
---|
169 | */
|
---|
170 | #ifndef EXPECT_100_THRESHOLD
|
---|
171 | #define EXPECT_100_THRESHOLD (1024*1024)
|
---|
172 | #endif
|
---|
173 |
|
---|
174 | /* MAX_HTTP_RESP_HEADER_SIZE is the maximum size of all response headers
|
---|
175 | combined that libcurl allows for a single HTTP response, any HTTP
|
---|
176 | version. This count includes CONNECT response headers. */
|
---|
177 | #define MAX_HTTP_RESP_HEADER_SIZE (300*1024)
|
---|
178 |
|
---|
179 | bool Curl_http_exp100_is_selected(struct Curl_easy *data);
|
---|
180 | void Curl_http_exp100_got100(struct Curl_easy *data);
|
---|
181 |
|
---|
182 | #endif /* CURL_DISABLE_HTTP */
|
---|
183 |
|
---|
184 | /****************************************************************************
|
---|
185 | * HTTP unique setup
|
---|
186 | ***************************************************************************/
|
---|
187 | struct HTTP {
|
---|
188 | #ifndef CURL_DISABLE_HTTP
|
---|
189 | void *h2_ctx; /* HTTP/2 implementation context */
|
---|
190 | void *h3_ctx; /* HTTP/3 implementation context */
|
---|
191 | #else
|
---|
192 | char unused;
|
---|
193 | #endif
|
---|
194 | };
|
---|
195 |
|
---|
196 | CURLcode Curl_http_size(struct Curl_easy *data);
|
---|
197 |
|
---|
198 | CURLcode Curl_http_write_resp_hds(struct Curl_easy *data,
|
---|
199 | const char *buf, size_t blen,
|
---|
200 | size_t *pconsumed);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Curl_http_output_auth() setups the authentication headers for the
|
---|
204 | * host/proxy and the correct authentication
|
---|
205 | * method. data->state.authdone is set to TRUE when authentication is
|
---|
206 | * done.
|
---|
207 | *
|
---|
208 | * @param data all information about the current transfer
|
---|
209 | * @param conn all information about the current connection
|
---|
210 | * @param request pointer to the request keyword
|
---|
211 | * @param httpreq is the request type
|
---|
212 | * @param path pointer to the requested path
|
---|
213 | * @param proxytunnel boolean if this is the request setting up a "proxy
|
---|
214 | * tunnel"
|
---|
215 | *
|
---|
216 | * @returns CURLcode
|
---|
217 | */
|
---|
218 | CURLcode
|
---|
219 | Curl_http_output_auth(struct Curl_easy *data,
|
---|
220 | struct connectdata *conn,
|
---|
221 | const char *request,
|
---|
222 | Curl_HttpReq httpreq,
|
---|
223 | const char *path,
|
---|
224 | bool proxytunnel); /* TRUE if this is the request setting
|
---|
225 | up the proxy tunnel */
|
---|
226 |
|
---|
227 | /* Decode HTTP status code string. */
|
---|
228 | CURLcode Curl_http_decode_status(int *pstatus, const char *s, size_t len);
|
---|
229 |
|
---|
230 |
|
---|
231 | /**
|
---|
232 | * All about a core HTTP request, excluding body and trailers
|
---|
233 | */
|
---|
234 | struct httpreq {
|
---|
235 | char method[24];
|
---|
236 | char *scheme;
|
---|
237 | char *authority;
|
---|
238 | char *path;
|
---|
239 | struct dynhds headers;
|
---|
240 | struct dynhds trailers;
|
---|
241 | };
|
---|
242 |
|
---|
243 | /**
|
---|
244 | * Create a HTTP request struct.
|
---|
245 | */
|
---|
246 | CURLcode Curl_http_req_make(struct httpreq **preq,
|
---|
247 | const char *method, size_t m_len,
|
---|
248 | const char *scheme, size_t s_len,
|
---|
249 | const char *authority, size_t a_len,
|
---|
250 | const char *path, size_t p_len);
|
---|
251 |
|
---|
252 | CURLcode Curl_http_req_make2(struct httpreq **preq,
|
---|
253 | const char *method, size_t m_len,
|
---|
254 | CURLU *url, const char *scheme_default);
|
---|
255 |
|
---|
256 | void Curl_http_req_free(struct httpreq *req);
|
---|
257 |
|
---|
258 | #define HTTP_PSEUDO_METHOD ":method"
|
---|
259 | #define HTTP_PSEUDO_SCHEME ":scheme"
|
---|
260 | #define HTTP_PSEUDO_AUTHORITY ":authority"
|
---|
261 | #define HTTP_PSEUDO_PATH ":path"
|
---|
262 | #define HTTP_PSEUDO_STATUS ":status"
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Create the list of HTTP/2 headers which represent the request,
|
---|
266 | * using HTTP/2 pseudo headers preceding the `req->headers`.
|
---|
267 | *
|
---|
268 | * Applies the following transformations:
|
---|
269 | * - if `authority` is set, any "Host" header is removed.
|
---|
270 | * - if `authority` is unset and a "Host" header is present, use
|
---|
271 | * that as `authority` and remove "Host"
|
---|
272 | * - removes and Connection header fields as defined in rfc9113 ch. 8.2.2
|
---|
273 | * - lower-cases the header field names
|
---|
274 | *
|
---|
275 | * @param h2_headers will contain the HTTP/2 headers on success
|
---|
276 | * @param req the request to transform
|
---|
277 | * @param data the handle to lookup defaults like ' :scheme' from
|
---|
278 | */
|
---|
279 | CURLcode Curl_http_req_to_h2(struct dynhds *h2_headers,
|
---|
280 | struct httpreq *req, struct Curl_easy *data);
|
---|
281 |
|
---|
282 | /**
|
---|
283 | * All about a core HTTP response, excluding body and trailers
|
---|
284 | */
|
---|
285 | struct http_resp {
|
---|
286 | int status;
|
---|
287 | char *description;
|
---|
288 | struct dynhds headers;
|
---|
289 | struct dynhds trailers;
|
---|
290 | struct http_resp *prev;
|
---|
291 | };
|
---|
292 |
|
---|
293 | /**
|
---|
294 | * Create a HTTP response struct.
|
---|
295 | */
|
---|
296 | CURLcode Curl_http_resp_make(struct http_resp **presp,
|
---|
297 | int status,
|
---|
298 | const char *description);
|
---|
299 |
|
---|
300 | void Curl_http_resp_free(struct http_resp *resp);
|
---|
301 |
|
---|
302 | #endif /* HEADER_CURL_HTTP_H */
|
---|