1 #ifndef HEADER_CURL_HTTP_H 2 #define HEADER_CURL_HTTP_H 3 /*************************************************************************** 4 * _ _ ____ _ 5 * Project ___| | | | _ \| | 6 * / __| | | | |_) | | 7 * | (__| |_| | _ <| |___ 8 * \___|\___/|_| \_\_____| 9 * 10 * Copyright (C) 1998 - 2020, 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.haxx.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 #ifndef CURL_DISABLE_HTTP 27 28 #ifdef USE_NGHTTP2 29 #include <nghttp2/nghttp2.h> 30 #endif 31 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 38 /* Header specific functions */ 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 43 char *Curl_copy_header_value(const char *header); 44 45 char *Curl_checkProxyheaders(const struct connectdata *conn, 46 const char *thisheader); 47 CURLcode Curl_buffer_send(struct dynbuf *in, 48 struct connectdata *conn, 49 curl_off_t *bytes_written, 50 size_t included_body_bytes, 51 int socketindex); 52 53 CURLcode Curl_add_timecondition(const struct connectdata *conn, 54 struct dynbuf *buf); 55 CURLcode Curl_add_custom_headers(struct connectdata *conn, 56 bool is_connect, 57 struct dynbuf *req_buffer); 58 CURLcode Curl_http_compile_trailers(struct curl_slist *trailers, 59 struct dynbuf *buf, 60 struct Curl_easy *handle); 61 62 /* protocol-specific functions set up to be called by the main engine */ 63 CURLcode Curl_http(struct connectdata *conn, bool *done); 64 CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature); 65 CURLcode Curl_http_connect(struct connectdata *conn, bool *done); 66 67 /* These functions are in http.c */ 68 CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy, 69 const char *auth); 70 CURLcode Curl_http_auth_act(struct connectdata *conn); 71 72 /* If only the PICKNONE bit is set, there has been a round-trip and we 73 selected to use no auth at all. Ie, we actively select no auth, as opposed 74 to not having one selected. The other CURLAUTH_* defines are present in the 75 public curl/curl.h header. */ 76 #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */ 77 78 /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST 79 data get included in the initial data chunk sent to the server. If the 80 data is larger than this, it will automatically get split up in multiple 81 system calls. 82 83 This value used to be fairly big (100K), but we must take into account that 84 if the server rejects the POST due for authentication reasons, this data 85 will always be unconditionally sent and thus it may not be larger than can 86 always be afforded to send twice. 87 88 It must not be greater than 64K to work on VMS. 89 */ 90 #ifndef MAX_INITIAL_POST_SIZE 91 #define MAX_INITIAL_POST_SIZE (64*1024) 92 #endif 93 94 /* EXPECT_100_THRESHOLD is the request body size limit for when libcurl will 95 * automatically add an "Expect: 100-continue" header in HTTP requests. When 96 * the size is unknown, it will always add it. 97 * 98 */ 99 #ifndef EXPECT_100_THRESHOLD 100 #define EXPECT_100_THRESHOLD (1024*1024) 101 #endif 102 103 #endif /* CURL_DISABLE_HTTP */ 104 105 #ifdef USE_NGHTTP3 106 struct h3out; /* see ngtcp2 */ 107 #endif 108 109 /**************************************************************************** 110 * HTTP unique setup 111 ***************************************************************************/ 112 struct HTTP { 113 curl_mimepart *sendit; 114 curl_off_t postsize; /* off_t to handle large file sizes */ 115 const char *postdata; 116 117 const char *p_pragma; /* Pragma: string */ 118 const char *p_accept; /* Accept: string */ 119 120 /* For FORM posting */ 121 curl_mimepart form; 122 123 struct back { 124 curl_read_callback fread_func; /* backup storage for fread pointer */ 125 void *fread_in; /* backup storage for fread_in pointer */ 126 const char *postdata; 127 curl_off_t postsize; 128 } backup; 129 130 enum { 131 HTTPSEND_NADA, /* init */ 132 HTTPSEND_REQUEST, /* sending a request */ 133 HTTPSEND_BODY, /* sending body */ 134 HTTPSEND_LAST /* never use this */ 135 } sending; 136 137 #ifndef CURL_DISABLE_HTTP 138 struct dynbuf send_buffer; /* used if the request couldn't be sent in one 139 chunk, points to an allocated send_buffer 140 struct */ 141 #endif 142 #ifdef USE_NGHTTP2 143 /*********** for HTTP/2 we store stream-local data here *************/ 144 int32_t stream_id; /* stream we are interested in */ 145 146 bool bodystarted; 147 /* We store non-final and final response headers here, per-stream */ 148 struct dynbuf header_recvbuf; 149 size_t nread_header_recvbuf; /* number of bytes in header_recvbuf fed into 150 upper layer */ 151 int status_code; /* HTTP status code */ 152 const uint8_t *pausedata; /* pointer to data received in on_data_chunk */ 153 size_t pauselen; /* the number of bytes left in data */ 154 bool close_handled; /* TRUE if stream closure is handled by libcurl */ 155 156 char **push_headers; /* allocated array */ 157 size_t push_headers_used; /* number of entries filled in */ 158 size_t push_headers_alloc; /* number of entries allocated */ 159 #endif 160 #if defined(USE_NGHTTP2) || defined(USE_NGHTTP3) 161 bool closed; /* TRUE on HTTP2 stream close */ 162 char *mem; /* points to a buffer in memory to store received data */ 163 size_t len; /* size of the buffer 'mem' points to */ 164 size_t memlen; /* size of data copied to mem */ 165 #endif 166 #if defined(USE_NGHTTP2) || defined(ENABLE_QUIC) 167 /* fields used by both HTTP/2 and HTTP/3 */ 168 const uint8_t *upload_mem; /* points to a buffer to read from */ 169 size_t upload_len; /* size of the buffer 'upload_mem' points to */ 170 curl_off_t upload_left; /* number of bytes left to upload */ 171 #endif 172 173 #ifdef ENABLE_QUIC 174 /*********** for HTTP/3 we store stream-local data here *************/ 175 int64_t stream3_id; /* stream we are interested in */ 176 bool firstheader; /* FALSE until headers arrive */ 177 bool firstbody; /* FALSE until body arrives */ 178 bool h3req; /* FALSE until request is issued */ 179 bool upload_done; 180 #endif 181 #ifdef USE_NGHTTP3 182 size_t unacked_window; 183 struct h3out *h3out; /* per-stream buffers for upload */ 184 struct dynbuf overflow; /* excess data received during a single Curl_read */ 185 #endif 186 }; 187 188 #ifdef USE_NGHTTP2 189 /* h2 settings for this connection */ 190 struct h2settings { 191 uint32_t max_concurrent_streams; 192 bool enable_push; 193 }; 194 #endif 195 196 struct http_conn { 197 #ifdef USE_NGHTTP2 198 #define H2_BINSETTINGS_LEN 80 199 nghttp2_session *h2; 200 uint8_t binsettings[H2_BINSETTINGS_LEN]; 201 size_t binlen; /* length of the binsettings data */ 202 Curl_send *send_underlying; /* underlying send Curl_send callback */ 203 Curl_recv *recv_underlying; /* underlying recv Curl_recv callback */ 204 char *inbuf; /* buffer to receive data from underlying socket */ 205 size_t inbuflen; /* number of bytes filled in inbuf */ 206 size_t nread_inbuf; /* number of bytes read from in inbuf */ 207 /* We need separate buffer for transmission and reception because we 208 may call nghttp2_session_send() after the 209 nghttp2_session_mem_recv() but mem buffer is still not full. In 210 this case, we wrongly sends the content of mem buffer if we share 211 them for both cases. */ 212 int32_t pause_stream_id; /* stream ID which paused 213 nghttp2_session_mem_recv */ 214 size_t drain_total; /* sum of all stream's UrlState.drain */ 215 216 /* this is a hash of all individual streams (Curl_easy structs) */ 217 struct h2settings settings; 218 219 /* list of settings that will be sent */ 220 nghttp2_settings_entry local_settings[3]; 221 size_t local_settings_num; 222 uint32_t error_code; /* HTTP/2 error code */ 223 #else 224 int unused; /* prevent a compiler warning */ 225 #endif 226 }; 227 228 CURLcode Curl_http_readwrite_headers(struct Curl_easy *data, 229 struct connectdata *conn, 230 ssize_t *nread, 231 bool *stop_reading); 232 233 /** 234 * Curl_http_output_auth() setups the authentication headers for the 235 * host/proxy and the correct authentication 236 * method. conn->data->state.authdone is set to TRUE when authentication is 237 * done. 238 * 239 * @param conn all information about the current connection 240 * @param request pointer to the request keyword 241 * @param path pointer to the requested path 242 * @param proxytunnel boolean if this is the request setting up a "proxy 243 * tunnel" 244 * 245 * @returns CURLcode 246 */ 247 CURLcode 248 Curl_http_output_auth(struct connectdata *conn, 249 const char *request, 250 const char *path, 251 bool proxytunnel); /* TRUE if this is the request setting 252 up the proxy tunnel */ 253 254 #endif /* HEADER_CURL_HTTP_H */ 255