Skip to content

[native] Fix blank HTTP Host header in requests #24929

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

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

ZacBlanco
Copy link
Contributor

@ZacBlanco ZacBlanco commented Apr 16, 2025

Description

This change properly sets the request destination address so that ensureHostHeader sets the correct value for the HTTP Host header.

Motivation and Context

Because the request's destination address wasn't set inside of the RequestBuilder object, the Host was populated with a blank value. On older HTTP servers this is permissible, but on newer ones (such as the incoming Jetty 12 upgrade), this is a hard error and results in the request being rejected with a 400 error.

Impact

N/A

Test Plan

Existing tests

Contributor checklist

  • Please make sure your submission complies with our contributing guide, in particular code style and commit standards.
  • PR description addresses the issue accurately and concisely. If the change is non-trivial, a GitHub Issue is referenced.
  • Documented new properties (with its default value), SQL syntax, functions, or other functionality.
  • If release notes are required, they follow the release notes guidelines.
  • Adequate tests were added if applicable.
  • CI passed.

Release Notes

== NO RELEASE NOTE ==

@prestodb-ci prestodb-ci added the from:IBM PR from IBM label Apr 16, 2025
@ZacBlanco ZacBlanco changed the title [native] Fix blank HTTP host header in requests [native] Fix blank HTTP Host header in requests Apr 16, 2025
@ZacBlanco ZacBlanco requested a review from pramodsatya April 16, 2025 22:16
pramodsatya
pramodsatya previously approved these changes Apr 16, 2025
Copy link
Contributor

@pramodsatya pramodsatya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ZacBlanco, LGTM.

@ZacBlanco ZacBlanco force-pushed the upstream-native-host-header branch from c669bee to 06fdfa6 Compare April 17, 2025 04:30
@ZacBlanco ZacBlanco marked this pull request as ready for review April 17, 2025 04:32
@ZacBlanco ZacBlanco requested a review from a team as a code owner April 17, 2025 04:32
@prestodb-ci prestodb-ci requested review from a team, nmahadevuni and namya28 and removed request for a team April 17, 2025 04:32
@@ -244,7 +244,6 @@ class RequestBuilder {
send(HttpClient* client, const std::string& body = "", int64_t delayMs = 0) {
addJwtIfConfigured();
header(proxygen::HTTP_HEADER_CONTENT_LENGTH, std::to_string(body.size()));
headers_.ensureHostHeader();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think send is used other places too, can this be left in?

Copy link
Contributor Author

@ZacBlanco ZacBlanco Apr 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is this will always set the Host header as an empty string because the HttpMessage doesn't have a dstAddress set. It isn't possible to get the dstAddress except for when the client actually sends the request. If the Host header gets set to empty, then subsequent calls to ensureHostHeader are a no-op

@ZacBlanco ZacBlanco force-pushed the upstream-native-host-header branch from 06fdfa6 to f08764e Compare April 21, 2025 13:42
Copy link
Contributor

@aditi-pandit aditi-pandit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ZacBlanco

Because the request's destination address wasn't set inside
of the RequestBuilder object, the Host was populated with
a blank value. On older HTTP versions this is permissible, but
on newer ones (such as Jetty 12), this is a hard error and results
in the request being rejected with a 400 error.

This change properly sets the request destination address so
that ensureHostHeader sets the correct value.
@ZacBlanco ZacBlanco force-pushed the upstream-native-host-header branch from f08764e to 7a445d8 Compare April 24, 2025 18:45
@ZacBlanco ZacBlanco merged commit 2d7abbc into prestodb:master Apr 25, 2025
105 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
from:IBM PR from IBM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants