VirtualBox

source: vbox/trunk/src/libs/curl-7.83.1/lib/http.h@ 97138

最後變更 在這個檔案從97138是 95312,由 vboxsync 提交於 3 年 前

libs/{curl,libxml2}: OSE export fixes, bugref:8515

  • 屬性 svn:eol-style 設為 native
檔案大小: 13.8 KB
 
1#ifndef HEADER_CURL_HTTP_H
2#define HEADER_CURL_HTTP_H
3/***************************************************************************
4 * _ _ ____ _
5 * Project ___| | | | _ \| |
6 * / __| | | | |_) | |
7 * | (__| |_| | _ <| |___
8 * \___|\___/|_| \_\_____|
9 *
10 * Copyright (C) 1998 - 2022, 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 ***************************************************************************/
24#include "curl_setup.h"
25
26typedef 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#if defined(_WIN32) && defined(ENABLE_QUIC)
42#include <stdint.h>
43#endif
44
45extern const struct Curl_handler Curl_handler_http;
46
47#ifdef USE_SSL
48extern const struct Curl_handler Curl_handler_https;
49#endif
50
51/* Header specific functions */
52bool Curl_compareheader(const char *headerline, /* line to check */
53 const char *header, /* header keyword _with_ colon */
54 const size_t hlen, /* len of the keyword in bytes */
55 const char *content, /* content string to find */
56 const size_t clen); /* len of the content in bytes */
57
58char *Curl_copy_header_value(const char *header);
59
60char *Curl_checkProxyheaders(struct Curl_easy *data,
61 const struct connectdata *conn,
62 const char *thisheader,
63 const size_t thislen);
64CURLcode Curl_buffer_send(struct dynbuf *in,
65 struct Curl_easy *data,
66 curl_off_t *bytes_written,
67 curl_off_t included_body_bytes,
68 int socketindex);
69
70CURLcode Curl_add_timecondition(struct Curl_easy *data,
71#ifndef USE_HYPER
72 struct dynbuf *req
73#else
74 void *headers
75#endif
76 );
77CURLcode Curl_add_custom_headers(struct Curl_easy *data,
78 bool is_connect,
79#ifndef USE_HYPER
80 struct dynbuf *req
81#else
82 void *headers
83#endif
84 );
85CURLcode Curl_http_compile_trailers(struct curl_slist *trailers,
86 struct dynbuf *buf,
87 struct Curl_easy *handle);
88
89void Curl_http_method(struct Curl_easy *data, struct connectdata *conn,
90 const char **method, Curl_HttpReq *);
91CURLcode Curl_http_useragent(struct Curl_easy *data);
92CURLcode Curl_http_host(struct Curl_easy *data, struct connectdata *conn);
93CURLcode Curl_http_target(struct Curl_easy *data, struct connectdata *conn,
94 struct dynbuf *req);
95CURLcode Curl_http_statusline(struct Curl_easy *data,
96 struct connectdata *conn);
97CURLcode Curl_http_header(struct Curl_easy *data, struct connectdata *conn,
98 char *headp);
99CURLcode Curl_transferencode(struct Curl_easy *data);
100CURLcode Curl_http_body(struct Curl_easy *data, struct connectdata *conn,
101 Curl_HttpReq httpreq,
102 const char **teep);
103CURLcode Curl_http_bodysend(struct Curl_easy *data, struct connectdata *conn,
104 struct dynbuf *r, Curl_HttpReq httpreq);
105bool Curl_use_http_1_1plus(const struct Curl_easy *data,
106 const struct connectdata *conn);
107#ifndef CURL_DISABLE_COOKIES
108CURLcode Curl_http_cookies(struct Curl_easy *data,
109 struct connectdata *conn,
110 struct dynbuf *r);
111#else
112#define Curl_http_cookies(a,b,c) CURLE_OK
113#endif
114CURLcode Curl_http_resume(struct Curl_easy *data,
115 struct connectdata *conn,
116 Curl_HttpReq httpreq);
117CURLcode Curl_http_range(struct Curl_easy *data,
118 Curl_HttpReq httpreq);
119CURLcode Curl_http_firstwrite(struct Curl_easy *data,
120 struct connectdata *conn,
121 bool *done);
122
123/* protocol-specific functions set up to be called by the main engine */
124CURLcode Curl_http(struct Curl_easy *data, bool *done);
125CURLcode Curl_http_done(struct Curl_easy *data, CURLcode, bool premature);
126CURLcode Curl_http_connect(struct Curl_easy *data, bool *done);
127
128/* These functions are in http.c */
129CURLcode Curl_http_input_auth(struct Curl_easy *data, bool proxy,
130 const char *auth);
131CURLcode Curl_http_auth_act(struct Curl_easy *data);
132
133/* If only the PICKNONE bit is set, there has been a round-trip and we
134 selected to use no auth at all. Ie, we actively select no auth, as opposed
135 to not having one selected. The other CURLAUTH_* defines are present in the
136 public curl/curl.h header. */
137#define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
138
139/* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
140 data get included in the initial data chunk sent to the server. If the
141 data is larger than this, it will automatically get split up in multiple
142 system calls.
143
144 This value used to be fairly big (100K), but we must take into account that
145 if the server rejects the POST due for authentication reasons, this data
146 will always be unconditionally sent and thus it may not be larger than can
147 always be afforded to send twice.
148
149 It must not be greater than 64K to work on VMS.
150*/
151#ifndef MAX_INITIAL_POST_SIZE
152#define MAX_INITIAL_POST_SIZE (64*1024)
153#endif
154
155/* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will
156 * automatically add an "Expect: 100-continue" header in HTTP requests. When
157 * the size is unknown, it will always add it.
158 *
159 */
160#ifndef EXPECT_100_THRESHOLD
161#define EXPECT_100_THRESHOLD (1024*1024)
162#endif
163
164#endif /* CURL_DISABLE_HTTP */
165
166#ifdef USE_NGHTTP3
167struct h3out; /* see ngtcp2 */
168#endif
169
170#ifdef USE_MSH3
171#ifdef _WIN32
172#define msh3_lock CRITICAL_SECTION
173#define msh3_lock_initialize(lock) InitializeCriticalSection(lock)
174#define msh3_lock_uninitialize(lock) DeleteCriticalSection(lock)
175#define msh3_lock_acquire(lock) EnterCriticalSection(lock)
176#define msh3_lock_release(lock) LeaveCriticalSection(lock)
177#else /* !_WIN32 */
178#include <pthread.h>
179#define msh3_lock pthread_mutex_t
180#define msh3_lock_initialize(lock) { \
181 pthread_mutexattr_t attr; \
182 pthread_mutexattr_init(&attr); \
183 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); \
184 pthread_mutex_init(lock, &attr); \
185 pthread_mutexattr_destroy(&attr); \
186}
187#define msh3_lock_uninitialize(lock) pthread_mutex_destroy(lock)
188#define msh3_lock_acquire(lock) pthread_mutex_lock(lock)
189#define msh3_lock_release(lock) pthread_mutex_unlock(lock)
190#endif /* _WIN32 */
191#endif /* USE_MSH3 */
192
193/****************************************************************************
194 * HTTP unique setup
195 ***************************************************************************/
196struct HTTP {
197 curl_mimepart *sendit;
198 curl_off_t postsize; /* off_t to handle large file sizes */
199 const char *postdata;
200
201 const char *p_pragma; /* Pragma: string */
202
203 /* For FORM posting */
204 curl_mimepart form;
205
206 struct back {
207 curl_read_callback fread_func; /* backup storage for fread pointer */
208 void *fread_in; /* backup storage for fread_in pointer */
209 const char *postdata;
210 curl_off_t postsize;
211 } backup;
212
213 enum {
214 HTTPSEND_NADA, /* init */
215 HTTPSEND_REQUEST, /* sending a request */
216 HTTPSEND_BODY /* sending body */
217 } sending;
218
219#ifndef CURL_DISABLE_HTTP
220 struct dynbuf send_buffer; /* used if the request couldn't be sent in one
221 chunk, points to an allocated send_buffer
222 struct */
223#endif
224#ifdef USE_NGHTTP2
225 /*********** for HTTP/2 we store stream-local data here *************/
226 int32_t stream_id; /* stream we are interested in */
227
228 bool bodystarted;
229 /* We store non-final and final response headers here, per-stream */
230 struct dynbuf header_recvbuf;
231 size_t nread_header_recvbuf; /* number of bytes in header_recvbuf fed into
232 upper layer */
233 struct dynbuf trailer_recvbuf;
234 int status_code; /* HTTP status code */
235 const uint8_t *pausedata; /* pointer to data received in on_data_chunk */
236 size_t pauselen; /* the number of bytes left in data */
237 bool close_handled; /* TRUE if stream closure is handled by libcurl */
238
239 char **push_headers; /* allocated array */
240 size_t push_headers_used; /* number of entries filled in */
241 size_t push_headers_alloc; /* number of entries allocated */
242 uint32_t error; /* HTTP/2 stream error code */
243#endif
244#if defined(USE_NGHTTP2) || defined(USE_NGHTTP3)
245 bool closed; /* TRUE on HTTP2 stream close */
246 char *mem; /* points to a buffer in memory to store received data */
247 size_t len; /* size of the buffer 'mem' points to */
248 size_t memlen; /* size of data copied to mem */
249#endif
250#if defined(USE_NGHTTP2) || defined(ENABLE_QUIC)
251 /* fields used by both HTTP/2 and HTTP/3 */
252 const uint8_t *upload_mem; /* points to a buffer to read from */
253 size_t upload_len; /* size of the buffer 'upload_mem' points to */
254 curl_off_t upload_left; /* number of bytes left to upload */
255#endif
256
257#ifdef ENABLE_QUIC
258#ifndef USE_MSH3
259 /*********** for HTTP/3 we store stream-local data here *************/
260 int64_t stream3_id; /* stream we are interested in */
261 bool firstheader; /* FALSE until headers arrive */
262 bool firstbody; /* FALSE until body arrives */
263 bool h3req; /* FALSE until request is issued */
264#endif
265 bool upload_done;
266#endif
267#ifdef USE_NGHTTP3
268 size_t unacked_window;
269 struct h3out *h3out; /* per-stream buffers for upload */
270 struct dynbuf overflow; /* excess data received during a single Curl_read */
271#endif
272#ifdef USE_MSH3
273 struct MSH3_REQUEST *req;
274 msh3_lock recv_lock;
275 /* Receive Buffer (Headers and Data) */
276 uint8_t* recv_buf;
277 size_t recv_buf_alloc;
278 /* Receive Headers */
279 size_t recv_header_len;
280 bool recv_header_complete;
281 /* Receive Data */
282 size_t recv_data_len;
283 bool recv_data_complete;
284 /* General Receive Error */
285 CURLcode recv_error;
286#endif
287};
288
289#ifdef USE_NGHTTP2
290/* h2 settings for this connection */
291struct h2settings {
292 uint32_t max_concurrent_streams;
293 bool enable_push;
294};
295#endif
296
297struct http_conn {
298#ifdef USE_NGHTTP2
299#define H2_BINSETTINGS_LEN 80
300 uint8_t binsettings[H2_BINSETTINGS_LEN];
301 size_t binlen; /* length of the binsettings data */
302
303 /* We associate the connnectdata struct with the connection, but we need to
304 make sure we can identify the current "driving" transfer. This is a
305 work-around for the lack of nghttp2_session_set_user_data() in older
306 nghttp2 versions that we want to support. (Added in 1.31.0) */
307 struct Curl_easy *trnsfr;
308
309 nghttp2_session *h2;
310 Curl_send *send_underlying; /* underlying send Curl_send callback */
311 Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */
312 char *inbuf; /* buffer to receive data from underlying socket */
313 size_t inbuflen; /* number of bytes filled in inbuf */
314 size_t nread_inbuf; /* number of bytes read from in inbuf */
315 /* We need separate buffer for transmission and reception because we
316 may call nghttp2_session_send() after the
317 nghttp2_session_mem_recv() but mem buffer is still not full. In
318 this case, we wrongly sends the content of mem buffer if we share
319 them for both cases. */
320 int32_t pause_stream_id; /* stream ID which paused
321 nghttp2_session_mem_recv */
322 size_t drain_total; /* sum of all stream's UrlState.drain */
323
324 /* this is a hash of all individual streams (Curl_easy structs) */
325 struct h2settings settings;
326
327 /* list of settings that will be sent */
328 nghttp2_settings_entry local_settings[3];
329 size_t local_settings_num;
330#else
331 int unused; /* prevent a compiler warning */
332#endif
333};
334
335CURLcode Curl_http_size(struct Curl_easy *data);
336
337CURLcode Curl_http_readwrite_headers(struct Curl_easy *data,
338 struct connectdata *conn,
339 ssize_t *nread,
340 bool *stop_reading);
341
342/**
343 * Curl_http_output_auth() setups the authentication headers for the
344 * host/proxy and the correct authentication
345 * method. data->state.authdone is set to TRUE when authentication is
346 * done.
347 *
348 * @param data all information about the current transfer
349 * @param conn all information about the current connection
350 * @param request pointer to the request keyword
351 * @param httpreq is the request type
352 * @param path pointer to the requested path
353 * @param proxytunnel boolean if this is the request setting up a "proxy
354 * tunnel"
355 *
356 * @returns CURLcode
357 */
358CURLcode
359Curl_http_output_auth(struct Curl_easy *data,
360 struct connectdata *conn,
361 const char *request,
362 Curl_HttpReq httpreq,
363 const char *path,
364 bool proxytunnel); /* TRUE if this is the request setting
365 up the proxy tunnel */
366
367/*
368 * Curl_allow_auth_to_host() tells if authentication, cookies or other
369 * "sensitive data" can (still) be sent to this host.
370 */
371bool Curl_allow_auth_to_host(struct Curl_easy *data);
372
373#endif /* HEADER_CURL_HTTP_H */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette