Skip to content

Commit a84a41f

Browse files
committed
Polishing contribution
Closes gh-33638
1 parent a78385f commit a84a41f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

framework-platform/framework-platform.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ dependencies {
5050
api("io.micrometer:context-propagation:1.1.1")
5151
api("io.mockk:mockk:1.13.4")
5252
api("io.projectreactor.netty:reactor-netty5-http:2.0.0-M3")
53-
api("io.projectreactor.netty:reactor-netty-http")
5453
api("io.projectreactor.tools:blockhound:1.0.8.RELEASE")
5554
api("io.r2dbc:r2dbc-h2:1.0.0.RELEASE")
5655
api("io.r2dbc:r2dbc-spi-test:1.0.0.RELEASE")

spring-web/src/main/java/org/springframework/http/server/reactive/ReactorUriHelper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,7 +24,7 @@
2424
import org.springframework.util.Assert;
2525

2626
/**
27-
* Helper class for creating a {@link URI} from a reactor {@link HttpServerRequest}.
27+
* Helper class to create {@link URI} from a Reactor Netty request.
2828
*
2929
* @author Arjen Poutsma
3030
* @since 6.0.8
@@ -48,12 +48,16 @@ public static URI createUri(HttpServerRequest request) throws URISyntaxException
4848
builder.append(port);
4949
}
5050

51+
// Reactor Netty has config whether to extract and apply forwarded headers.
52+
// We apply the prefix manually as it affects the contextPath too.
53+
5154
String prefix = request.forwardedPrefix();
5255
if (prefix != null && !prefix.isEmpty()) {
5356
builder.append(prefix);
5457
}
5558

5659
appendRequestUri(request, builder);
60+
5761
return new URI(builder.toString());
5862
}
5963

spring-web/src/test/java/org/springframework/http/server/reactive/ReactorUriHelperTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import static org.mockito.Mockito.mock;
3030

3131
/**
32+
* Unit tests for {@link ReactorUriHelper}.
33+
*
3234
* @author Arjen Poutsma
3335
*/
3436
class ReactorUriHelperTests {
@@ -58,14 +60,14 @@ void hostnameWithZoneId() throws URISyntaxException {
5860
" | /",
5961
"'' | /",
6062
})
61-
void forwardedPrefix(String prefixHeader, String expectedPath) throws URISyntaxException {
63+
void forwardedPrefix(String forwardedPrefixHeader, String expectedPath) throws URISyntaxException {
6264
HttpServerRequest nettyRequest = mock();
6365

6466
given(nettyRequest.scheme()).willReturn("https");
6567
given(nettyRequest.hostName()).willReturn("localhost");
6668
given(nettyRequest.hostPort()).willReturn(443);
6769
given(nettyRequest.uri()).willReturn("/");
68-
given(nettyRequest.forwardedPrefix()).willReturn(prefixHeader);
70+
given(nettyRequest.forwardedPrefix()).willReturn(forwardedPrefixHeader);
6971

7072
URI uri = ReactorUriHelper.createUri(nettyRequest);
7173
assertThat(uri).hasScheme("https")
@@ -75,5 +77,4 @@ void forwardedPrefix(String prefixHeader, String expectedPath) throws URISyntaxE
7577
.hasToString("https://localhost" + expectedPath);
7678
}
7779

78-
7980
}

0 commit comments

Comments
 (0)