]> granicus.if.org Git - curl/commitdiff
http2: do the POST Upgrade dance properly
authorDaniel Stenberg <daniel@haxx.se>
Thu, 30 Jan 2014 13:26:00 +0000 (14:26 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 30 Jan 2014 13:26:00 +0000 (14:26 +0100)
lib/http.h
lib/http2.c
lib/http2.h

index 8d3f9d0d0fad2f4b935146fef9a7329f7c1f1a83..228e375eb486a5b3cebe81b1a094e69a2b5bef85 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -151,7 +151,10 @@ struct HTTP {
 
 struct http_conn {
 #ifdef USE_NGHTTP2
+#define H2_BINSETTINGS_LEN 80
   nghttp2_session *h2;
+  uint8_t binsettings[H2_BINSETTINGS_LEN];
+  size_t  binlen; /* length of the binsettings data */
   char *mem;     /* points to a buffer in memory to store or read from */
   size_t size;   /* size of the buffer 'mem' points to */
   ssize_t nread; /* how much data that was sent/recv by the HTTP2 engine */
index 126a8128895fec32670cb023f5919cfbf86ebcd1..a5b01e35d85cdce2b4ff4a6fc42291b97838bcb1 100644 (file)
@@ -320,12 +320,12 @@ CURLcode Curl_http2_send_request(struct connectdata *conn)
 CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
                                     struct connectdata *conn)
 {
-  uint8_t binsettings[80];
   CURLcode result;
   ssize_t binlen;
   char *base64;
   size_t blen;
   struct SingleRequest *k = &conn->data->req;
+  uint8_t *binsettings = conn->proto.httpc.binsettings;
 
   Curl_http2_init(conn);
 
@@ -335,14 +335,14 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
    */
 
   /* this returns number of bytes it wrote */
-  binlen = nghttp2_pack_settings_payload(binsettings,
-                                         sizeof(binsettings),
+  binlen = nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN,
                                          settings,
                                          sizeof(settings)/sizeof(settings[0]));
   if(!binlen) {
     failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
     return CURLE_FAILED_INIT;
   }
+  conn->proto.httpc.binlen = binlen;
 
   result = Curl_base64_encode(conn->data, (const char *)binsettings, binlen,
                               &base64, &blen);
@@ -397,13 +397,20 @@ static ssize_t http2_send(struct connectdata *conn, int sockindex,
   return 0;
 }
 
-void Curl_http2_switched(struct connectdata *conn)
+int Curl_http2_switched(struct connectdata *conn)
 {
+  int rc;
+  struct http_conn *httpc = &conn->proto.httpc;
   /* we are switched! */
   conn->handler = &Curl_handler_http2;
   conn->recv[FIRSTSOCKET] = http2_recv;
   conn->send[FIRSTSOCKET] = http2_send;
   infof(conn->data, "We have switched to HTTP2\n");
+
+  /* send the SETTINGS frame (again) */
+  rc = nghttp2_session_upgrade(httpc->h2, httpc->binsettings, httpc->binlen,
+                               conn);
+  return rc;
 }
 
 #endif
index c6a5c41dcb9bdc61b691f014bf92d3f1f27fa399..ef994b7ba1f9da7e17cd2af70f2992214d6edf26 100644 (file)
@@ -36,7 +36,7 @@ CURLcode Curl_http2_init(struct connectdata *conn);
 CURLcode Curl_http2_send_request(struct connectdata *conn);
 CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
                                     struct connectdata *conn);
-void Curl_http2_switched(struct connectdata *conn);
+int Curl_http2_switched(struct connectdata *conn);
 #else /* USE_NGHTTP2 */
 #define Curl_http2_init(x)
 #define Curl_http2_send_request(x)