mirror of
https://github.com/moparisthebest/curl
synced 2024-12-22 08:08:50 -05:00
http2: disable server push if not requested
Ref: https://github.com/curl/curl/pull/1160
This commit is contained in:
parent
02ee3b2737
commit
9ad034e5a1
@ -219,6 +219,10 @@ struct http_conn {
|
|||||||
|
|
||||||
/* this is a hash of all individual streams (Curl_easy structs) */
|
/* this is a hash of all individual streams (Curl_easy structs) */
|
||||||
struct h2settings settings;
|
struct h2settings settings;
|
||||||
|
|
||||||
|
/* list of settings that will be sent */
|
||||||
|
nghttp2_settings_entry local_settings[3];
|
||||||
|
size_t local_settings_num;
|
||||||
#else
|
#else
|
||||||
int unused; /* prevent a compiler warning */
|
int unused; /* prevent a compiler warning */
|
||||||
#endif
|
#endif
|
||||||
|
42
lib/http2.c
42
lib/http2.c
@ -967,14 +967,6 @@ static ssize_t data_source_read_callback(nghttp2_session *session,
|
|||||||
return nread;
|
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
|
#define H2_BUFSIZE 32768
|
||||||
|
|
||||||
#ifdef NGHTTP2_HAS_ERROR_CALLBACK
|
#ifdef NGHTTP2_HAS_ERROR_CALLBACK
|
||||||
@ -990,6 +982,23 @@ static int error_callback(nghttp2_session *session,
|
|||||||
}
|
}
|
||||||
#endif
|
#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)
|
void Curl_http2_done(struct connectdata *conn, bool premature)
|
||||||
{
|
{
|
||||||
struct Curl_easy *data = conn->data;
|
struct Curl_easy *data = conn->data;
|
||||||
@ -1103,16 +1112,14 @@ CURLcode Curl_http2_request_upgrade(Curl_send_buffer *req,
|
|||||||
size_t blen;
|
size_t blen;
|
||||||
struct SingleRequest *k = &conn->data->req;
|
struct SingleRequest *k = &conn->data->req;
|
||||||
uint8_t *binsettings = conn->proto.httpc.binsettings;
|
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
|
populate_settings(conn, httpc);
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* this returns number of bytes it wrote */
|
/* this returns number of bytes it wrote */
|
||||||
binlen = nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN,
|
binlen = nghttp2_pack_settings_payload(binsettings, H2_BINSETTINGS_LEN,
|
||||||
settings,
|
httpc->local_settings,
|
||||||
sizeof(settings)/sizeof(settings[0]));
|
httpc->local_settings_num);
|
||||||
if(!binlen) {
|
if(!binlen) {
|
||||||
failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
|
failf(conn->data, "nghttp2 unexpectedly failed on pack_settings_payload");
|
||||||
return CURLE_FAILED_INIT;
|
return CURLE_FAILED_INIT;
|
||||||
@ -2031,10 +2038,13 @@ CURLcode Curl_http2_switched(struct connectdata *conn,
|
|||||||
conn->data);
|
conn->data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
populate_settings(conn, httpc);
|
||||||
|
|
||||||
/* stream ID is unknown at this point */
|
/* stream ID is unknown at this point */
|
||||||
stream->stream_id = -1;
|
stream->stream_id = -1;
|
||||||
rv = nghttp2_submit_settings(httpc->h2, NGHTTP2_FLAG_NONE, settings,
|
rv = nghttp2_submit_settings(httpc->h2, NGHTTP2_FLAG_NONE,
|
||||||
sizeof(settings) / sizeof(settings[0]));
|
httpc->local_settings,
|
||||||
|
httpc->local_settings_num);
|
||||||
if(rv != 0) {
|
if(rv != 0) {
|
||||||
failf(data, "nghttp2_submit_settings() failed: %s(%d)",
|
failf(data, "nghttp2_submit_settings() failed: %s(%d)",
|
||||||
nghttp2_strerror(rv), rv);
|
nghttp2_strerror(rv), rv);
|
||||||
|
@ -48,7 +48,7 @@ Host: %HOSTIP:%HTTPPORT
|
|||||||
Accept: */*
|
Accept: */*
|
||||||
Connection: Upgrade, HTTP2-Settings
|
Connection: Upgrade, HTTP2-Settings
|
||||||
Upgrade: %H2CVER
|
Upgrade: %H2CVER
|
||||||
HTTP2-Settings: AAMAAABkAARAAAAA
|
HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
|
||||||
|
|
||||||
</protocol>
|
</protocol>
|
||||||
</verify>
|
</verify>
|
||||||
|
@ -58,7 +58,7 @@ Host: %HOSTIP:%HTTPPORT
|
|||||||
Accept: */*
|
Accept: */*
|
||||||
Connection: Upgrade, HTTP2-Settings
|
Connection: Upgrade, HTTP2-Settings
|
||||||
Upgrade: %H2CVER
|
Upgrade: %H2CVER
|
||||||
HTTP2-Settings: AAMAAABkAARAAAAA
|
HTTP2-Settings: AAMAAABkAARAAAAAAAIAAAAA
|
||||||
|
|
||||||
</protocol>
|
</protocol>
|
||||||
# CURLE_HTTP2: Send failure: Broken pipe
|
# CURLE_HTTP2: Send failure: Broken pipe
|
||||||
|
Loading…
Reference in New Issue
Block a user