Skip to content
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

absoluteURI is null when host header is missing #2596

Open
rmartinc opened this issue Apr 13, 2024 · 1 comment
Open

absoluteURI is null when host header is missing #2596

rmartinc opened this issue Apr 13, 2024 · 1 comment
Assignees
Labels
Milestone

Comments

@rmartinc
Copy link

Version

4.5.7 but it's in master too.

Context

There is very weird behavior in HttpServerrequest between vert.x and vertx-web. In vert.x when the host header is missing it returns null for authority() but returns an URI in absoluteURI(). Project vert.x executes some code to return the absolute URI based on the server origin. Nevertheless vertx-web returns null in both methods. Reading the javadoc for HttpServerRequest I think that authority can be null but absoluteURI not. I'm not happy with this because I don't understand that absoluteURI has an authority filled but the specific authority method returns null, but OK, I accept it. But then can vertx-web do the same?

I added this little diff to do the same in vertx-web too. I'm assigning initially the aboluteURI to the one returned by vert.x and modifying the testMissingHostHeader to assert is not null.

diff --git a/vertx-web/src/main/java/io/vertx/ext/web/impl/ForwardedParser.java b/vertx-web/src/main/java/io/vertx/ext/web/impl/ForwardedParser.java
index 557d6225e..53007ef51 100644
--- a/vertx-web/src/main/java/io/vertx/ext/web/impl/ForwardedParser.java
+++ b/vertx-web/src/main/java/io/vertx/ext/web/impl/ForwardedParser.java
@@ -106,6 +106,7 @@ class ForwardedParser {
     remoteAddress = delegate.remoteAddress();
     scheme = delegate.scheme();
     setHostAndPort(delegate.authority());
+    absoluteURI = delegate.absoluteURI();
 
     switch (allowForward) {
       case X_FORWARD:
diff --git a/vertx-web/src/test/java/io/vertx/ext/web/ForwardedTest.java b/vertx-web/src/test/java/io/vertx/ext/web/ForwardedTest.java
index 2ed5e479b..5bf378a4c 100644
--- a/vertx-web/src/test/java/io/vertx/ext/web/ForwardedTest.java
+++ b/vertx-web/src/test/java/io/vertx/ext/web/ForwardedTest.java
@@ -433,6 +433,7 @@ public class ForwardedTest extends WebTestBase {
 
     route.handler(rc -> {
       assertNull(rc.request().authority());
+      assertNotNull(rc.request().absoluteURI());
       rc.end();
     });

Do you have a reproducer?

You can execute your own test ForwardedTest#testMissingHostHeader you will see that authority() is null (as in vert.x) but absolutyURI() is also null (while in vert.x is http://localhost:8080/).

@rmartinc rmartinc added the bug label Apr 13, 2024
@rmartinc
Copy link
Author

I have asked also about the authority and absoluteURI discrepancy in the vert.x google groups: https://groups.google.com/g/vertx/c/OBffuFH-WZU

@tsegismont tsegismont self-assigned this Apr 15, 2024
@tsegismont tsegismont added this to the 4.5.8 milestone Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants