http2: add CRLF when first data arrives
[platform/upstream/curl.git] / lib / http.h
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
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 char *Curl_checkheaders(struct SessionHandle *data, const char *thisheader);
43 char *Curl_copy_header_value(const char *header);
44
45 /* ------------------------------------------------------------------------- */
46 /*
47  * The add_buffer series of functions are used to build one large memory chunk
48  * from repeated function invokes. Used so that the entire HTTP request can
49  * be sent in one go.
50  */
51 struct Curl_send_buffer {
52   char *buffer;
53   size_t size_max;
54   size_t size_used;
55 };
56 typedef struct Curl_send_buffer Curl_send_buffer;
57
58 Curl_send_buffer *Curl_add_buffer_init(void);
59 CURLcode Curl_add_bufferf(Curl_send_buffer *in, const char *fmt, ...);
60 CURLcode Curl_add_buffer(Curl_send_buffer *in, const void *inptr, size_t size);
61 CURLcode Curl_add_buffer_send(Curl_send_buffer *in,
62                               struct connectdata *conn,
63                               long *bytes_written,
64                               size_t included_body_bytes,
65                               int socketindex);
66
67 CURLcode Curl_add_timecondition(struct SessionHandle *data,
68                                 Curl_send_buffer *buf);
69 CURLcode Curl_add_custom_headers(struct connectdata *conn,
70                                    Curl_send_buffer *req_buffer);
71
72 /* protocol-specific functions set up to be called by the main engine */
73 CURLcode Curl_http(struct connectdata *conn, bool *done);
74 CURLcode Curl_http_done(struct connectdata *, CURLcode, bool premature);
75 CURLcode Curl_http_connect(struct connectdata *conn, bool *done);
76 CURLcode Curl_http_setup_conn(struct connectdata *conn);
77
78 /* The following functions are defined in http_chunks.c */
79 void Curl_httpchunk_init(struct connectdata *conn);
80 CHUNKcode Curl_httpchunk_read(struct connectdata *conn, char *datap,
81                               ssize_t length, ssize_t *wrote);
82
83 /* These functions are in http.c */
84 void Curl_http_auth_stage(struct SessionHandle *data, int stage);
85 CURLcode Curl_http_input_auth(struct connectdata *conn, bool proxy,
86                               const char *auth);
87 CURLcode Curl_http_auth_act(struct connectdata *conn);
88 CURLcode Curl_http_perhapsrewind(struct connectdata *conn);
89
90 /* If only the PICKNONE bit is set, there has been a round-trip and we
91    selected to use no auth at all. Ie, we actively select no auth, as opposed
92    to not having one selected. The other CURLAUTH_* defines are present in the
93    public curl/curl.h header. */
94 #define CURLAUTH_PICKNONE (1<<30) /* don't use auth */
95
96 /* MAX_INITIAL_POST_SIZE indicates the number of bytes that will make the POST
97    data get included in the initial data chunk sent to the server. If the
98    data is larger than this, it will automatically get split up in multiple
99    system calls.
100
101    This value used to be fairly big (100K), but we must take into account that
102    if the server rejects the POST due for authentication reasons, this data
103    will always be uncondtionally sent and thus it may not be larger than can
104    always be afforded to send twice.
105
106    It must not be greater than 64K to work on VMS.
107 */
108 #ifndef MAX_INITIAL_POST_SIZE
109 #define MAX_INITIAL_POST_SIZE (64*1024)
110 #endif
111
112 #ifndef TINY_INITIAL_POST_SIZE
113 #define TINY_INITIAL_POST_SIZE 1024
114 #endif
115
116 #endif /* CURL_DISABLE_HTTP */
117
118 /****************************************************************************
119  * HTTP unique setup
120  ***************************************************************************/
121 struct HTTP {
122   struct FormData *sendit;
123   curl_off_t postsize; /* off_t to handle large file sizes */
124   const char *postdata;
125
126   const char *p_pragma;      /* Pragma: string */
127   const char *p_accept;      /* Accept: string */
128   curl_off_t readbytecount;
129   curl_off_t writebytecount;
130
131   /* For FORM posting */
132   struct Form form;
133
134   struct back {
135     curl_read_callback fread_func; /* backup storage for fread pointer */
136     void *fread_in;           /* backup storage for fread_in pointer */
137     const char *postdata;
138     curl_off_t postsize;
139   } backup;
140
141   enum {
142     HTTPSEND_NADA,    /* init */
143     HTTPSEND_REQUEST, /* sending a request */
144     HTTPSEND_BODY,    /* sending body */
145     HTTPSEND_LAST     /* never use this */
146   } sending;
147
148   void *send_buffer; /* used if the request couldn't be sent in one chunk,
149                         points to an allocated send_buffer struct */
150 };
151
152 struct http_conn {
153 #ifdef USE_NGHTTP2
154 #define H2_BINSETTINGS_LEN 80
155   nghttp2_session *h2;
156   uint8_t binsettings[H2_BINSETTINGS_LEN];
157   size_t  binlen; /* length of the binsettings data */
158   char *mem;     /* points to a buffer in memory to store or read from */
159   size_t len;    /* size of the buffer 'mem' points to */
160   bool bodystarted;
161 #else
162   int unused; /* prevent a compiler warning */
163 #endif
164 };
165
166 CURLcode Curl_http_readwrite_headers(struct SessionHandle *data,
167                                      struct connectdata *conn,
168                                      ssize_t *nread,
169                                      bool *stop_reading);
170
171 /**
172  * Curl_http_output_auth() setups the authentication headers for the
173  * host/proxy and the correct authentication
174  * method. conn->data->state.authdone is set to TRUE when authentication is
175  * done.
176  *
177  * @param conn all information about the current connection
178  * @param request pointer to the request keyword
179  * @param path pointer to the requested path
180  * @param proxytunnel boolean if this is the request setting up a "proxy
181  * tunnel"
182  *
183  * @returns CURLcode
184  */
185 CURLcode
186 Curl_http_output_auth(struct connectdata *conn,
187                       const char *request,
188                       const char *path,
189                       bool proxytunnel); /* TRUE if this is the request setting
190                                             up the proxy tunnel */
191
192 #endif /* HEADER_CURL_HTTP_H */
193