]> granicus.if.org Git - curl/commitdiff
http2: disable server push if not requested
authorAlessandro Ghedini <alessandro@ghedini.me>
Sat, 10 Dec 2016 13:54:59 +0000 (13:54 +0000)
committerAlessandro Ghedini <alessandro@ghedini.me>
Sun, 15 Jan 2017 11:45:32 +0000 (11:45 +0000)
Ref: https://github.com/curl/curl/pull/1160

lib/http.h
lib/http2.c
tests/data/test1800
tests/data/test1801

index 9fb669c9d589eac74abac8852796eb745a6e1f75..7ce4bd9a0f70a90bc52042eeadcb20522cc9be0d 100644 (file)
@@ -219,6 +219,10 @@ struct http_conn {
 
   /* this is a hash of all individual streams (Curl_easy structs) */
   struct h2settings settings;
+
+  /* list of settings that will be sent */
+  nghttp2_settings_entry local_settings[3];
+  size_t local_settings_num;
 #else
   int unused; /* prevent a compiler warning */
 #endif
index 9088f4dffe600701f726dff4afaa3b8f9b3df8fa..4d108da44968d8cac5aa6f6877e2b25e7568670f 100644 (file)
@@ -967,14 +967,6 @@ static ssize_t data_source_read_callback(nghttp2_session *session,
   return nread;
 }
 
-/*
- * The HTTP2 settings we send in the Upgrade request
- */
-static nghttp2_settings_entry settings[] = {
-  { NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 100 },
-  { NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, HTTP2_HUGE_WINDOW_SIZE },
-};
-
 #define H2_BUFSIZE 32768
 
 #ifdef NGHTTP2_HAS_ERROR_CALLBACK
@@ -990,6 +982,23 @@ static int error_callback(nghttp2_session *session,
 }
 #endif
 
+static void populate_settings(struct connectdata *conn,
+                              struct http_conn *httpc)
+{
+  nghttp2_settings_entry *iv = httpc->local_settings;
+
+  iv[0].settings_id = NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS;
+  iv[0].value = 100;
+
+  iv[1].settings_id = NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
+  iv[1].value = HTTP2_HUGE_WINDOW_SIZE;
+
+  iv[2].settings_id = NGHTTP2_SETTINGS_ENABLE_PUSH;
+  iv[2].value = conn->data->multi->push_cb != NULL;
+
+  httpc->local_settings_num = 3;
+}
+
 void Curl_http2_done(struct connectdata *conn, bool premature)
 {
   struct Curl_easy *data = conn->data;
@@ -1103,16 +1112,14 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
   size_t blen;
   struct SingleRequest *k = &conn->data->req;
   uint8_t *binsettings = conn->proto.httpc.binsettings;
+  struct http_conn *httpc = &conn->proto.httpc;
 
-  /* As long as we have a fixed set of settings, we don't have to dynamically
-   * figure out the base64 strings since it'll always be the same. However,
-   * the settings will likely not be fixed every time in the future.
-   */
+  populate_settings(conn, httpc);
 
   /* this returns number of bytes it wrote */
   binlen = nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN,
-                                         settings,
-                                         sizeof(settings)/sizeof(settings[0]));
+                                         httpc->local_settings,
+                                         httpc->local_settings_num);
   if(!binlen) {
     failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
     return CURLE_FAILED_INIT;
@@ -2031,10 +2038,13 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
                                          conn->data);
   }
   else {
+    populate_settings(conn, httpc);
+
     /* stream ID is unknown at this point */
     stream->stream_id = -1;
-    rv = nghttp2_submit_settings(httpc->h2, NGHTTP2_FLAG_NONE, settings,
-                                 sizeof(settings) / sizeof(settings[0]));
+    rv = nghttp2_submit_settings(httpc->h2, NGHTTP2_FLAG_NONE,
+                                 httpc->local_settings,
+                                 httpc->local_settings_num);
     if(rv != 0) {
       failf(data, "nghttp2_submit_settings() failed: %s(%d)",
             nghttp2_strerror(rv), rv);
index 0a2bb1f6df37d982bbbd09e9cf240d6a7cdde2e9..011018400132be7a7363d6d221f7b3e779b7193c 100644 (file)
@@ -48,7 +48,7 @@ Host: %HOSTIP:%HTTPPORT
 Accept: */*\r
 Connection: Upgrade, HTTP2-Settings\r
 Upgrade: %H2CVER\r
-HTTP2-Settings: AAMAAABkAARAAAAA\r
+HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA\r
 \r
 </protocol>
 </verify>
index 9e1900b9e7b9fcaf777dd088f95b6f5f621285cc..b827ab51ee6c5aedd996bb64fa74cb34e72cc9bf 100644 (file)
@@ -58,7 +58,7 @@ Host: %HOSTIP:%HTTPPORT
 Accept: */*\r
 Connection: Upgrade, HTTP2-Settings\r
 Upgrade: %H2CVER\r
-HTTP2-Settings: AAMAAABkAARAAAAA\r
+HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA\r
 \r
 </protocol>
 # CURLE_HTTP2: Send failure: Broken pipe