nghttpx: Enable websocket over h3

This commit is contained in:
Tatsuhiro Tsujikawa 2021-09-11 17:56:25 +09:00
parent 0066bf8eed
commit ccaf2333ca
4 changed files with 19 additions and 4 deletions

View File

@ -896,7 +896,8 @@ bool Downstream::get_non_final_response() const {
} }
bool Downstream::supports_non_final_response() const { bool Downstream::supports_non_final_response() const {
return req_.http_major == 2 || (req_.http_major == 1 && req_.http_minor == 1); return req_.http_major == 3 || req_.http_major == 2 ||
(req_.http_major == 1 && req_.http_minor == 1);
} }
bool Downstream::get_upgraded() const { return upgraded_; } bool Downstream::get_upgraded() const { return upgraded_; }
@ -947,7 +948,8 @@ bool Downstream::expect_response_trailer() const {
// In HTTP/2, if final response HEADERS does not bear END_STREAM it // In HTTP/2, if final response HEADERS does not bear END_STREAM it
// is possible trailer fields might come, regardless of request // is possible trailer fields might come, regardless of request
// method or status code. // method or status code.
return !resp_.headers_only && resp_.http_major == 2; return !resp_.headers_only &&
(resp_.http_major == 3 || resp_.http_major == 2);
} }
namespace { namespace {

View File

@ -168,6 +168,11 @@ void test_downstream_supports_non_final_response(void) {
Downstream d(nullptr, nullptr, 0); Downstream d(nullptr, nullptr, 0);
auto &req = d.request(); auto &req = d.request();
req.http_major = 3;
req.http_minor = 0;
CU_ASSERT(d.supports_non_final_response());
req.http_major = 2; req.http_major = 2;
req.http_minor = 0; req.http_minor = 0;

View File

@ -2312,10 +2312,16 @@ int Http3Upstream::setup_httpconn() {
shrpx::http_reset_stream, shrpx::http_reset_stream,
}; };
auto config = get_config();
nghttp3_settings settings; nghttp3_settings settings;
nghttp3_settings_default(&settings); nghttp3_settings_default(&settings);
settings.qpack_max_table_capacity = 4_k; settings.qpack_max_table_capacity = 4_k;
if (!config->http2_proxy) {
settings.enable_connect_protocol = 1;
}
auto mem = nghttp3_mem_default(); auto mem = nghttp3_mem_default();
rv = nghttp3_conn_server_new(&httpconn_, &callbacks, &settings, mem, this); rv = nghttp3_conn_server_new(&httpconn_, &callbacks, &settings, mem, this);

View File

@ -523,7 +523,9 @@ int HttpDownstreamConnection::push_request_headers() {
(xffconf.strip_incoming ? http2::HDOP_STRIP_X_FORWARDED_FOR : 0) | (xffconf.strip_incoming ? http2::HDOP_STRIP_X_FORWARDED_FOR : 0) |
(xfpconf.strip_incoming ? http2::HDOP_STRIP_X_FORWARDED_PROTO : 0) | (xfpconf.strip_incoming ? http2::HDOP_STRIP_X_FORWARDED_PROTO : 0) |
(earlydataconf.strip_incoming ? http2::HDOP_STRIP_EARLY_DATA : 0) | (earlydataconf.strip_incoming ? http2::HDOP_STRIP_EARLY_DATA : 0) |
(req.http_major == 2 ? http2::HDOP_STRIP_SEC_WEBSOCKET_KEY : 0); ((req.http_major == 3 || req.http_major == 2)
? http2::HDOP_STRIP_SEC_WEBSOCKET_KEY
: 0);
http2::build_http1_headers_from_headers(buf, req.fs.headers(), build_flags); http2::build_http1_headers_from_headers(buf, req.fs.headers(), build_flags);
@ -543,7 +545,7 @@ int HttpDownstreamConnection::push_request_headers() {
} }
if (req.connect_proto == ConnectProto::WEBSOCKET) { if (req.connect_proto == ConnectProto::WEBSOCKET) {
if (req.http_major == 2) { if (req.http_major == 3 || req.http_major == 2) {
std::array<uint8_t, 16> nonce; std::array<uint8_t, 16> nonce;
if (RAND_bytes(nonce.data(), nonce.size()) != 1) { if (RAND_bytes(nonce.data(), nonce.size()) != 1) {
return -1; return -1;