Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 1 | #ifndef HEADER_CURL_HTTP_H |
| 2 | #define HEADER_CURL_HTTP_H |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 3 | /*************************************************************************** |
| 4 | * _ _ ____ _ |
| 5 | * Project ___| | | | _ \| | |
| 6 | * / __| | | | |_) | | |
| 7 | * | (__| |_| | _ <| |___ |
| 8 | * \___|\___/|_| \_\_____| |
| 9 | * |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 10 | * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 14 | * are also available at https://curl.haxx.se/docs/copyright.html. |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 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 | ***************************************************************************/ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 24 | #include "curl_setup.h" |
| 25 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 26 | #ifndef CURL_DISABLE_HTTP |
| 27 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 28 | #ifdef USE_NGHTTP2 |
| 29 | #include <nghttp2/nghttp2.h> |
| 30 | #endif |
| 31 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 32 | extern const struct Curl_handler Curl_handler_http; |
| 33 | |
| 34 | #ifdef USE_SSL |
| 35 | extern const struct Curl_handler Curl_handler_https; |
| 36 | #endif |
| 37 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 38 | /* Header specific functions */ |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 39 | bool Curl_compareheader(const char *headerline, /* line to check */ |
| 40 | const char *header, /* header keyword _with_ colon */ |
| 41 | const char *content); /* content string to find */ |
| 42 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 43 | char *Curl_copy_header_value(const char *header); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 44 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 45 | char *Curl_checkProxyheaders(const struct connectdata *conn, |
| 46 | const char *thisheader); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 47 | /* ------------------------------------------------------------------------- */ |
| 48 | /* |
| 49 | * The add_buffer series of functions are used to build one large memory chunk |
| 50 | * from repeated function invokes. Used so that the entire HTTP request can |
| 51 | * be sent in one go. |
| 52 | */ |
| 53 | struct Curl_send_buffer { |
| 54 | char *buffer; |
| 55 | size_t size_max; |
| 56 | size_t size_used; |
| 57 | }; |
| 58 | typedef struct Curl_send_buffer Curl_send_buffer; |
| 59 | |
| 60 | Curl_send_buffer *Curl_add_buffer_init(void); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 61 | void Curl_add_buffer_free(Curl_send_buffer *buff); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 62 | CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...); |
| 63 | CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size); |
| 64 | CURLcode Curl_add_buffer_send(Curl_send_buffer *in, |
Lucas Eckels | 9bd90e6 | 2012-08-06 15:07:02 -0700 | [diff] [blame] | 65 | struct connectdata *conn, |
| 66 | long *bytes_written, |
| 67 | size_t included_body_bytes, |
| 68 | int socketindex); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 69 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 70 | CURLcode Curl_add_timecondition(struct Curl_easy *data, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 71 | Curl_send_buffer *buf); |
| 72 | CURLcode Curl_add_custom_headers(struct connectdata *conn, |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 73 | bool is_connect, |
| 74 | Curl_send_buffer *req_buffer); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 75 | |
| 76 | /* protocol-specific functions set up to be called by the main engine */ |
| 77 | CURLcode Curl_http(struct connectdata *conn, bool *done); |
| 78 | CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature); |
| 79 | CURLcode Curl_http_connect(struct connectdata *conn, bool *done); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 80 | CURLcode Curl_http_setup_conn(struct connectdata *conn); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 81 | |
| 82 | /* The following functions are defined in http_chunks.c */ |
| 83 | void Curl_httpchunk_init(struct connectdata *conn); |
| 84 | CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap, |
| 85 | ssize_t length, ssize_t *wrote); |
| 86 | |
| 87 | /* These functions are in http.c */ |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 88 | void Curl_http_auth_stage(struct Curl_easy *data, int stage); |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 89 | CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy, |
| 90 | const char *auth); |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 91 | CURLcode Curl_http_auth_act(struct connectdata *conn); |
| 92 | CURLcode Curl_http_perhapsrewind(struct connectdata *conn); |
| 93 | |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 94 | /* If only the PICKNONE bit is set, there has been a round-trip and we |
| 95 | selected to use no auth at all. Ie, we actively select no auth, as opposed |
| 96 | to not having one selected. The other CURLAUTH_* defines are present in the |
| 97 | public curl/curl.h header. */ |
| 98 | #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */ |
| 99 | |
| 100 | /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST |
| 101 | data get included in the initial data chunk sent to the server. If the |
| 102 | data is larger than this, it will automatically get split up in multiple |
| 103 | system calls. |
| 104 | |
| 105 | This value used to be fairly big (100K), but we must take into account that |
| 106 | if the server rejects the POST due for authentication reasons, this data |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 107 | will always be unconditionally sent and thus it may not be larger than can |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 108 | always be afforded to send twice. |
| 109 | |
| 110 | It must not be greater than 64K to work on VMS. |
| 111 | */ |
| 112 | #ifndef MAX_INITIAL_POST_SIZE |
| 113 | #define MAX_INITIAL_POST_SIZE (64*1024) |
| 114 | #endif |
| 115 | |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 116 | /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will |
| 117 | * automatically add an "Expect: 100-continue" header in HTTP requests. When |
| 118 | * the size is unknown, it will always add it. |
| 119 | * |
| 120 | */ |
| 121 | #ifndef EXPECT_100_THRESHOLD |
| 122 | #define EXPECT_100_THRESHOLD 1024 |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 123 | #endif |
| 124 | |
| 125 | #endif /* CURL_DISABLE_HTTP */ |
| 126 | |
| 127 | /**************************************************************************** |
| 128 | * HTTP unique setup |
| 129 | ***************************************************************************/ |
| 130 | struct HTTP { |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 131 | curl_mimepart *sendit; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 132 | curl_off_t postsize; /* off_t to handle large file sizes */ |
| 133 | const char *postdata; |
| 134 | |
| 135 | const char *p_pragma; /* Pragma: string */ |
| 136 | const char *p_accept; /* Accept: string */ |
| 137 | curl_off_t readbytecount; |
| 138 | curl_off_t writebytecount; |
| 139 | |
| 140 | /* For FORM posting */ |
Alex Deymo | 486467e | 2017-12-19 19:04:07 +0100 | [diff] [blame] | 141 | curl_mimepart form; |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 142 | |
| 143 | struct back { |
| 144 | curl_read_callback fread_func; /* backup storage for fread pointer */ |
| 145 | void *fread_in; /* backup storage for fread_in pointer */ |
| 146 | const char *postdata; |
| 147 | curl_off_t postsize; |
| 148 | } backup; |
| 149 | |
| 150 | enum { |
| 151 | HTTPSEND_NADA, /* init */ |
| 152 | HTTPSEND_REQUEST, /* sending a request */ |
| 153 | HTTPSEND_BODY, /* sending body */ |
| 154 | HTTPSEND_LAST /* never use this */ |
| 155 | } sending; |
| 156 | |
| 157 | void *send_buffer; /* used if the request couldn't be sent in one chunk, |
| 158 | points to an allocated send_buffer struct */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 159 | |
| 160 | #ifdef USE_NGHTTP2 |
| 161 | /*********** for HTTP/2 we store stream-local data here *************/ |
| 162 | int32_t stream_id; /* stream we are interested in */ |
| 163 | |
| 164 | bool bodystarted; |
| 165 | /* We store non-final and final response headers here, per-stream */ |
| 166 | Curl_send_buffer *header_recvbuf; |
| 167 | size_t nread_header_recvbuf; /* number of bytes in header_recvbuf fed into |
| 168 | upper layer */ |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 169 | Curl_send_buffer *trailer_recvbuf; |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 170 | int status_code; /* HTTP status code */ |
| 171 | const uint8_t *pausedata; /* pointer to data received in on_data_chunk */ |
| 172 | size_t pauselen; /* the number of bytes left in data */ |
| 173 | bool closed; /* TRUE on HTTP2 stream close */ |
Elliott Hughes | cee0338 | 2017-06-23 12:17:18 -0700 | [diff] [blame] | 174 | bool close_handled; /* TRUE if stream closure is handled by libcurl */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 175 | char *mem; /* points to a buffer in memory to store received data */ |
| 176 | size_t len; /* size of the buffer 'mem' points to */ |
| 177 | size_t memlen; /* size of data copied to mem */ |
| 178 | |
| 179 | const uint8_t *upload_mem; /* points to a buffer to read from */ |
| 180 | size_t upload_len; /* size of the buffer 'upload_mem' points to */ |
| 181 | curl_off_t upload_left; /* number of bytes left to upload */ |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 182 | |
| 183 | char **push_headers; /* allocated array */ |
| 184 | size_t push_headers_used; /* number of entries filled in */ |
| 185 | size_t push_headers_alloc; /* number of entries allocated */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 186 | #endif |
| 187 | }; |
| 188 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 189 | #ifdef USE_NGHTTP2 |
| 190 | /* h2 settings for this connection */ |
| 191 | struct h2settings { |
| 192 | uint32_t max_concurrent_streams; |
| 193 | bool enable_push; |
| 194 | }; |
| 195 | #endif |
| 196 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 197 | struct http_conn { |
| 198 | #ifdef USE_NGHTTP2 |
| 199 | #define H2_BINSETTINGS_LEN 80 |
| 200 | nghttp2_session *h2; |
| 201 | uint8_t binsettings[H2_BINSETTINGS_LEN]; |
| 202 | size_t binlen; /* length of the binsettings data */ |
Elliott Hughes | 1ef06ba | 2018-05-30 15:43:58 -0700 | [diff] [blame] | 203 | Curl_send *send_underlying; /* underlying send Curl_send callback */ |
| 204 | Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 205 | char *inbuf; /* buffer to receive data from underlying socket */ |
| 206 | size_t inbuflen; /* number of bytes filled in inbuf */ |
| 207 | size_t nread_inbuf; /* number of bytes read from in inbuf */ |
| 208 | /* We need separate buffer for transmission and reception because we |
| 209 | may call nghttp2_session_send() after the |
| 210 | nghttp2_session_mem_recv() but mem buffer is still not full. In |
| 211 | this case, we wrongly sends the content of mem buffer if we share |
| 212 | them for both cases. */ |
| 213 | int32_t pause_stream_id; /* stream ID which paused |
| 214 | nghttp2_session_mem_recv */ |
Alex Deymo | d15eaac | 2016-06-28 14:49:26 -0700 | [diff] [blame] | 215 | size_t drain_total; /* sum of all stream's UrlState.drain */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 216 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 217 | /* this is a hash of all individual streams (Curl_easy structs) */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 218 | struct h2settings settings; |
Elliott Hughes | 82be86d | 2017-09-20 17:00:17 -0700 | [diff] [blame] | 219 | |
| 220 | /* list of settings that will be sent */ |
| 221 | nghttp2_settings_entry local_settings[3]; |
| 222 | size_t local_settings_num; |
Elliott Hughes | cac3980 | 2018-04-27 16:19:43 -0700 | [diff] [blame] | 223 | uint32_t error_code; /* HTTP/2 error code */ |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 224 | #else |
| 225 | int unused; /* prevent a compiler warning */ |
| 226 | #endif |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 227 | }; |
| 228 | |
Alex Deymo | e3149cc | 2016-10-05 11:18:42 -0700 | [diff] [blame] | 229 | CURLcode Curl_http_readwrite_headers(struct Curl_easy *data, |
Kristian Monsen | 5ab5018 | 2010-05-14 18:53:44 +0100 | [diff] [blame] | 230 | struct connectdata *conn, |
| 231 | ssize_t *nread, |
| 232 | bool *stop_reading); |
| 233 | |
Bertrand SIMONNET | e6cd738 | 2015-07-01 15:39:44 -0700 | [diff] [blame] | 234 | /** |
| 235 | * Curl_http_output_auth() setups the authentication headers for the |
| 236 | * host/proxy and the correct authentication |
| 237 | * method. conn->data->state.authdone is set to TRUE when authentication is |
| 238 | * done. |
| 239 | * |
| 240 | * @param conn all information about the current connection |
| 241 | * @param request pointer to the request keyword |
| 242 | * @param path pointer to the requested path |
| 243 | * @param proxytunnel boolean if this is the request setting up a "proxy |
| 244 | * tunnel" |
| 245 | * |
| 246 | * @returns CURLcode |
| 247 | */ |
| 248 | CURLcode |
| 249 | Curl_http_output_auth(struct connectdata *conn, |
| 250 | const char *request, |
| 251 | const char *path, |
| 252 | bool proxytunnel); /* TRUE if this is the request setting |
| 253 | up the proxy tunnel */ |
| 254 | |
| 255 | #endif /* HEADER_CURL_HTTP_H */ |
| 256 | |