Skip to content

Commit 611e04b

Browse files
committed
h2: client: offer extensions on ws-over-h2 extended CONNECT
The h1 upgrade offers the vhost's extensions in sec-websocket-extensions, but lws_h2_client_handshake() only emitted sec-websocket-version and sec-websocket-protocol -- so an lws client could never negotiate permessage-deflate (or any extension) over h2, even against a server that supports it. RFC 8441 Sect 5 carries the ws handshake headers unchanged over extended CONNECT, so build the same offer list as lws_generate_client_ws_handshake() and emit it after the pseudo-headers. The response side already instantiates accepted extensions in the shared lws_client_ws_upgrade() path.
1 parent 3cc03ce commit 611e04b

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

lib/roles/h2/http2.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2870,6 +2870,40 @@ lws_h2_client_handshake(struct lws *wsi)
28702870
goto fail_length;
28712871
}
28722872

2873+
#if !defined(LWS_WITHOUT_EXTENSIONS)
2874+
{
2875+
/*
2876+
* Offer the vhost's extensions the same way the h1
2877+
* upgrade does (RFC 8441 Sect 5 carries the ws
2878+
* headers unchanged): without this the client can
2879+
* never negotiate eg, permessage-deflate over h2.
2880+
*/
2881+
const struct lws_extension *ext =
2882+
wsi->a.vhost->ws.extensions;
2883+
char eb[256];
2884+
int el = 0;
2885+
2886+
while (ext && ext->callback) {
2887+
if (wsi->a.vhost->protocols[0].callback(wsi,
2888+
LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED,
2889+
wsi->user_space, (char *)ext->name, 0)) {
2890+
ext++;
2891+
continue;
2892+
}
2893+
el += lws_snprintf(eb + (size_t)el,
2894+
sizeof(eb) - (size_t)el,
2895+
"%s%s", el ? "," : "",
2896+
ext->client_offer);
2897+
ext++;
2898+
}
2899+
if (el &&
2900+
lws_add_http_header_by_token(wsi,
2901+
WSI_TOKEN_EXTENSIONS,
2902+
(unsigned char *)eb, el, &p, end))
2903+
goto fail_length;
2904+
}
2905+
#endif
2906+
28732907
wsi->h23_stream_carries_ws = 1;
28742908
}
28752909
#endif

0 commit comments

Comments
 (0)