2
0

http.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef HEADER_CURL_HTTP_H
  2. #define HEADER_CURL_HTTP_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 1998 - 2014, 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 http://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. #ifndef CURL_DISABLE_HTTP
  26. #ifdef USE_NGHTTP2
  27. #include <nghttp2/nghttp2.h>
  28. #endif
  29. extern const struct Curl_handler Curl_handler_http;
  30. #ifdef USE_SSL
  31. extern const struct Curl_handler Curl_handler_https;
  32. #endif
  33. /* Header specific functions */
  34. bool Curl_compareheader(const char *headerline, /* line to check */
  35. const char *header, /* header keyword _with_ colon */
  36. const char *content); /* content string to find */
  37. char *Curl_checkheaders(const struct connectdata *conn,
  38. const char *thisheader);
  39. char *Curl_copy_header_value(const char *header);
  40. char *Curl_checkProxyheaders(const struct connectdata *conn,
  41. const char *thisheader);
  42. /* ------------------------------------------------------------------------- */
  43. /*
  44. * The add_buffer series of functions are used to build one large memory chunk
  45. * from repeated function invokes. Used so that the entire HTTP request can
  46. * be sent in one go.
  47. */
  48. struct Curl_send_buffer {
  49. char *buffer;
  50. size_t size_max;
  51. size_t size_used;
  52. };
  53. typedef struct Curl_send_buffer Curl_send_buffer;
  54. Curl_send_buffer *Curl_add_buffer_init(void);
  55. CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
  56. CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
  57. CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
  58. struct connectdata *conn,
  59. long *bytes_written,
  60. size_t included_body_bytes,
  61. int socketindex);
  62. CURLcode Curl_add_timecondition(struct SessionHandle *data,
  63. Curl_send_buffer *buf);
  64. CURLcode Curl_add_custom_headers(struct connectdata *conn,
  65. bool is_connect,
  66. Curl_send_buffer *req_buffer);
  67. /* protocol-specific functions set up to be called by the main engine */
  68. CURLcode Curl_http(struct connectdata *conn, bool *done);
  69. CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
  70. CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
  71. CURLcode Curl_http_setup_conn(struct connectdata *conn);
  72. /* The following functions are defined in http_chunks.c */
  73. void Curl_httpchunk_init(struct connectdata *conn);
  74. CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
  75. ssize_t length, ssize_t *wrote);
  76. /* These functions are in http.c */
  77. void Curl_http_auth_stage(struct SessionHandle *data, int stage);
  78. CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
  79. const char *auth);
  80. CURLcode Curl_http_auth_act(struct connectdata *conn);
  81. CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
  82. /* If only the PICKNONE bit is set, there has been a round-trip and we
  83. selected to use no auth at all. Ie, we actively select no auth, as opposed
  84. to not having one selected. The other CURLAUTH_* defines are present in the
  85. public curl/curl.h header. */
  86. #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
  87. /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
  88. data get included in the initial data chunk sent to the server. If the
  89. data is larger than this, it will automatically get split up in multiple
  90. system calls.
  91. This value used to be fairly big (100K), but we must take into account that
  92. if the server rejects the POST due for authentication reasons, this data
  93. will always be uncondtionally sent and thus it may not be larger than can
  94. always be afforded to send twice.
  95. It must not be greater than 64K to work on VMS.
  96. */
  97. #ifndef MAX_INITIAL_POST_SIZE
  98. #define MAX_INITIAL_POST_SIZE (64*1024)
  99. #endif
  100. #ifndef TINY_INITIAL_POST_SIZE
  101. #define TINY_INITIAL_POST_SIZE 1024
  102. #endif
  103. #endif /* CURL_DISABLE_HTTP */
  104. /****************************************************************************
  105. * HTTP unique setup
  106. ***************************************************************************/
  107. struct HTTP {
  108. struct FormData *sendit;
  109. curl_off_t postsize; /* off_t to handle large file sizes */
  110. const char *postdata;
  111. const char *p_pragma; /* Pragma: string */
  112. const char *p_accept; /* Accept: string */
  113. curl_off_t readbytecount;
  114. curl_off_t writebytecount;
  115. /* For FORM posting */
  116. struct Form form;
  117. struct back {
  118. curl_read_callback fread_func; /* backup storage for fread pointer */
  119. void *fread_in; /* backup storage for fread_in pointer */
  120. const char *postdata;
  121. curl_off_t postsize;
  122. } backup;
  123. enum {
  124. HTTPSEND_NADA, /* init */
  125. HTTPSEND_REQUEST, /* sending a request */
  126. HTTPSEND_BODY, /* sending body */
  127. HTTPSEND_LAST /* never use this */
  128. } sending;
  129. void *send_buffer; /* used if the request couldn't be sent in one chunk,
  130. points to an allocated send_buffer struct */
  131. };
  132. typedef int (*sending)(void); /* Curl_send */
  133. typedef int (*recving)(void); /* Curl_recv */
  134. struct http_conn {
  135. #ifdef USE_NGHTTP2
  136. #define H2_BINSETTINGS_LEN 80
  137. nghttp2_session *h2;
  138. uint8_t binsettings[H2_BINSETTINGS_LEN];
  139. size_t binlen; /* length of the binsettings data */
  140. char *mem; /* points to a buffer in memory to store */
  141. size_t len; /* size of the buffer 'mem' points to */
  142. bool bodystarted;
  143. sending send_underlying; /* underlying send Curl_send callback */
  144. recving recv_underlying; /* underlying recv Curl_recv callback */
  145. bool closed; /* TRUE on HTTP2 stream close */
  146. Curl_send_buffer *header_recvbuf; /* store response headers. We
  147. store non-final and final
  148. response headers into it. */
  149. size_t nread_header_recvbuf; /* number of bytes in header_recvbuf
  150. fed into upper layer */
  151. int32_t stream_id; /* stream we are interested in */
  152. const uint8_t *data; /* pointer to data chunk, received in
  153. on_data_chunk */
  154. size_t datalen; /* the number of bytes left in data */
  155. char *inbuf; /* buffer to receive data from underlying socket */
  156. /* We need separate buffer for transmission and reception because we
  157. may call nghttp2_session_send() after the
  158. nghttp2_session_mem_recv() but mem buffer is still not full. In
  159. this case, we wrongly sends the content of mem buffer if we share
  160. them for both cases. */
  161. const uint8_t *upload_mem; /* points to a buffer to read from */
  162. size_t upload_len; /* size of the buffer 'upload_mem' points to */
  163. size_t upload_left; /* number of bytes left to upload */
  164. int status_code; /* HTTP status code */
  165. #else
  166. int unused; /* prevent a compiler warning */
  167. #endif
  168. };
  169. CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
  170. struct connectdata *conn,
  171. ssize_t *nread,
  172. bool *stop_reading);
  173. /**
  174. * Curl_http_output_auth() setups the authentication headers for the
  175. * host/proxy and the correct authentication
  176. * method. conn->data->state.authdone is set to TRUE when authentication is
  177. * done.
  178. *
  179. * @param conn all information about the current connection
  180. * @param request pointer to the request keyword
  181. * @param path pointer to the requested path
  182. * @param proxytunnel boolean if this is the request setting up a "proxy
  183. * tunnel"
  184. *
  185. * @returns CURLcode
  186. */
  187. CURLcode
  188. Curl_http_output_auth(struct connectdata *conn,
  189. const char *request,
  190. const char *path,
  191. bool proxytunnel); /* TRUE if this is the request setting
  192. up the proxy tunnel */
  193. #endif /* HEADER_CURL_HTTP_H */