http2: first embryo toward Upgrade:
[platform/upstream/curl.git] / lib / http2.c
1 /***************************************************************************
2  *                                  _   _ ____  _
3  *  Project                     ___| | | |  _ \| |
4  *                             / __| | | | |_) | |
5  *                            | (__| |_| |  _ <| |___
6  *                             \___|\___/|_| \_\_____|
7  *
8  * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
9  *
10  * This software is licensed as described in the file COPYING, which
11  * you should have received as part of this distribution. The terms
12  * are also available at http://curl.haxx.se/docs/copyright.html.
13  *
14  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15  * copies of the Software, and permit persons to whom the Software is
16  * furnished to do so, under the terms of the COPYING file.
17  *
18  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19  * KIND, either express or implied.
20  *
21  ***************************************************************************/
22
23 #include "curl_setup.h"
24
25 #ifdef USE_NGHTTP2
26 #define _MPRINTF_REPLACE
27 #include <curl/mprintf.h>
28
29 #include <nghttp2/nghttp2.h>
30 #include "urldata.h"
31 #include "http2.h"
32 #include "http.h"
33
34 /*
35  * Store nghttp2 version info in this buffer, Prefix with a space.  Return
36  * total length written.
37  */
38 int Curl_http2_ver(char *p, size_t len)
39 {
40   nghttp2_info *h2 = nghttp2_version(0);
41   return snprintf(p, len, " nghttp2/%s", h2->version_str);
42 }
43
44 /*
45  * Append headers to ask for a HTTP1.1 to HTTP2 upgrade.
46  */
47 CURLcode Curl_http2_request(Curl_send_buffer *req,
48                             struct connectdata *conn)
49 {
50   const char *base64="AABBCC"; /* a fake string to start with */
51   CURLcode result =
52     Curl_add_bufferf(req,
53                      "Connection: Upgrade, HTTP2-Settings\r\n"
54                      "Upgrade: HTTP/2.0\r\n"
55                      "HTTP2-Settings: %s\r\n",
56                      base64);
57   (void)conn;
58   return result;
59 }
60
61 #endif