|
17 | 17 | #include "common/http/codes.h" |
18 | 18 | #include "common/http/exception.h" |
19 | 19 | #include "common/http/headers.h" |
20 | | -#include "common/http/utility.h" |
21 | 20 |
|
22 | 21 | namespace Envoy { |
23 | 22 | namespace Http { |
@@ -90,7 +89,15 @@ void ConnectionImpl::StreamImpl::encode100ContinueHeaders(const HeaderMap& heade |
90 | 89 |
|
91 | 90 | void ConnectionImpl::StreamImpl::encodeHeaders(const HeaderMap& headers, bool end_stream) { |
92 | 91 | std::vector<nghttp2_nv> final_headers; |
93 | | - buildHeaders(final_headers, headers); |
| 92 | + |
| 93 | + Http::HeaderMapPtr modified_headers; |
| 94 | + if (Http::Utility::isUpgrade(headers)) { |
| 95 | + modified_headers = std::make_unique<Http::HeaderMapImpl>(headers); |
| 96 | + transformUpgradeFromH1toH2(*modified_headers); |
| 97 | + buildHeaders(final_headers, *modified_headers); |
| 98 | + } else { |
| 99 | + buildHeaders(final_headers, headers); |
| 100 | + } |
94 | 101 |
|
95 | 102 | nghttp2_data_provider provider; |
96 | 103 | if (!end_stream) { |
@@ -151,6 +158,11 @@ void ConnectionImpl::StreamImpl::pendingRecvBufferLowWatermark() { |
151 | 158 | readDisable(false); |
152 | 159 | } |
153 | 160 |
|
| 161 | +void ConnectionImpl::StreamImpl::decodeHeaders() { |
| 162 | + maybeTransformUpgradeFromH2ToH1(); |
| 163 | + decoder_->decodeHeaders(std::move(headers_), remote_end_stream_); |
| 164 | +} |
| 165 | + |
154 | 166 | void ConnectionImpl::StreamImpl::pendingSendBufferHighWatermark() { |
155 | 167 | ENVOY_CONN_LOG(debug, "send buffer over limit ", parent_.connection_); |
156 | 168 | ASSERT(!pending_send_buffer_high_watermark_called_); |
@@ -366,13 +378,13 @@ int ConnectionImpl::onFrameReceived(const nghttp2_frame* frame) { |
366 | 378 | ASSERT(!stream->remote_end_stream_); |
367 | 379 | stream->decoder_->decode100ContinueHeaders(std::move(stream->headers_)); |
368 | 380 | } else { |
369 | | - stream->decoder_->decodeHeaders(std::move(stream->headers_), stream->remote_end_stream_); |
| 381 | + stream->decodeHeaders(); |
370 | 382 | } |
371 | 383 | break; |
372 | 384 | } |
373 | 385 |
|
374 | 386 | case NGHTTP2_HCAT_REQUEST: { |
375 | | - stream->decoder_->decodeHeaders(std::move(stream->headers_), stream->remote_end_stream_); |
| 387 | + stream->decodeHeaders(); |
376 | 388 | break; |
377 | 389 | } |
378 | 390 |
|
@@ -401,7 +413,7 @@ int ConnectionImpl::onFrameReceived(const nghttp2_frame* frame) { |
401 | 413 | // start out with. In this case, raise as headers. nghttp2 message checking guarantees |
402 | 414 | // proper flow here. |
403 | 415 | ASSERT(!stream->headers_->Status() || stream->headers_->Status()->value() != "100"); |
404 | | - stream->decoder_->decodeHeaders(std::move(stream->headers_), stream->remote_end_stream_); |
| 416 | + stream->decodeHeaders(); |
405 | 417 | } |
406 | 418 | } |
407 | 419 |
|
@@ -734,6 +746,10 @@ ConnectionImpl::Http2Options::Http2Options(const Http2Settings& http2_settings) |
734 | 746 | if (http2_settings.hpack_table_size_ != NGHTTP2_DEFAULT_HEADER_TABLE_SIZE) { |
735 | 747 | nghttp2_option_set_max_deflate_dynamic_table_size(options_, http2_settings.hpack_table_size_); |
736 | 748 | } |
| 749 | + if (http2_settings.allow_connect_) { |
| 750 | + // TODO(alyssawilk) change to ENABLE_CONNECT_PROTOCOL when it's available. |
| 751 | + nghttp2_option_set_no_http_messaging(options_, 1); |
| 752 | + } |
737 | 753 | } |
738 | 754 |
|
739 | 755 | ConnectionImpl::Http2Options::~Http2Options() { nghttp2_option_del(options_); } |
|
0 commit comments