-
Notifications
You must be signed in to change notification settings - Fork 5.6k
transport_socket(http_11_proxy): add Proxy-Authorization header support #46675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ | |
| #include "source/common/config/well_known_names.h" | ||
| #include "source/common/http/header_utility.h" | ||
| #include "source/common/network/address_impl.h" | ||
| #include "source/common/protobuf/protobuf.h" | ||
| #include "source/common/protobuf/utility.h" | ||
| #include "source/common/runtime/runtime_features.h" | ||
|
|
||
| namespace Envoy { | ||
|
|
@@ -69,8 +71,13 @@ UpstreamHttp11ConnectSocket::UpstreamHttp11ConnectSocket( | |
| } | ||
|
|
||
| // Helper method to create a properly formatted CONNECT request with Host header. | ||
| std::string UpstreamHttp11ConnectSocket::formatConnectRequest(absl::string_view target) { | ||
| return absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n", "Host: ", target, "\r\n\r\n"); | ||
| std::string UpstreamHttp11ConnectSocket::formatConnectRequest(absl::string_view target, | ||
| absl::string_view authentication) { | ||
| if (authentication.empty()) { | ||
| return absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n", "Host: ", target, "\r\n\r\n"); | ||
| } | ||
| return absl::StrCat("CONNECT ", target, " HTTP/1.1\r\n", "Host: ", target, "\r\n", | ||
| "Proxy-Authorization: ", authentication, "\r\n\r\n"); | ||
| } | ||
|
|
||
| inline void UpstreamHttp11ConnectSocket::handleProxyInfoConnect( | ||
|
|
@@ -93,6 +100,19 @@ inline void UpstreamHttp11ConnectSocket::handleProxyInfoConnect( | |
|
|
||
| inline void UpstreamHttp11ConnectSocket::handleHostMetadataConnect( | ||
| std::shared_ptr<const Upstream::HostDescription> host) { | ||
| // Look up the optional Proxy-Authorization value from the endpoint's typed metadata. | ||
| std::string authentication; | ||
| if (host->metadata() != nullptr) { | ||
| auto auth_it = host->metadata()->typed_filter_metadata().find( | ||
| Config::MetadataFilters::get().ENVOY_HTTP11_PROXY_TRANSPORT_SOCKET_AUTH); | ||
| if (auth_it != host->metadata()->typed_filter_metadata().end()) { | ||
| Protobuf::StringValue auth_value; | ||
| if (MessageUtil::unpackTo(auth_it->second, auth_value).ok()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this fails, we should emit some kind of trace log. |
||
| authentication = auth_value.value(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!Runtime::runtimeFeatureEnabled( | ||
| "envoy.reloadable_features.http_11_proxy_connect_legacy_format")) { | ||
| // Prefer <host-name>:<port> for RFC 9110 compliance, unless URI is <host-ip>:<port>. | ||
|
|
@@ -103,11 +123,16 @@ inline void UpstreamHttp11ConnectSocket::handleHostMetadataConnect( | |
| } else { | ||
| target = host->address()->asStringView(); | ||
| } | ||
| header_buffer_.add(formatConnectRequest(target)); | ||
| header_buffer_.add(formatConnectRequest(target, authentication)); | ||
| } else { | ||
| // Legacy behavior: <host-ip>:<port> format, no Host header for backward compatibility. | ||
| header_buffer_.add( | ||
| absl::StrCat("CONNECT ", host->address()->asStringView(), " HTTP/1.1\r\n\r\n")); | ||
| if (authentication.empty()) { | ||
| header_buffer_.add( | ||
| absl::StrCat("CONNECT ", host->address()->asStringView(), " HTTP/1.1\r\n\r\n")); | ||
| } else { | ||
| header_buffer_.add(absl::StrCat("CONNECT ", host->address()->asStringView(), " HTTP/1.1\r\n", | ||
| "Proxy-Authorization: ", authentication, "\r\n\r\n")); | ||
| } | ||
|
Comment on lines
+129
to
+135
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this nesting is getting out of hand. Can you pull out this and similar string building logic above into a common helper function? |
||
| } | ||
| need_to_strip_connect_response_ = true; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update the documentation with this.