parent
a78385f8e5
commit
a84a41fa43
|
@ -50,7 +50,6 @@ dependencies {
|
||||||
api("io.micrometer:context-propagation:1.1.1")
|
api("io.micrometer:context-propagation:1.1.1")
|
||||||
api("io.mockk:mockk:1.13.4")
|
api("io.mockk:mockk:1.13.4")
|
||||||
api("io.projectreactor.netty:reactor-netty5-http:2.0.0-M3")
|
api("io.projectreactor.netty:reactor-netty5-http:2.0.0-M3")
|
||||||
api("io.projectreactor.netty:reactor-netty-http")
|
|
||||||
api("io.projectreactor.tools:blockhound:1.0.8.RELEASE")
|
api("io.projectreactor.tools:blockhound:1.0.8.RELEASE")
|
||||||
api("io.r2dbc:r2dbc-h2:1.0.0.RELEASE")
|
api("io.r2dbc:r2dbc-h2:1.0.0.RELEASE")
|
||||||
api("io.r2dbc:r2dbc-spi-test:1.0.0.RELEASE")
|
api("io.r2dbc:r2dbc-spi-test:1.0.0.RELEASE")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2023 the original author or authors.
|
* Copyright 2002-2024 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -24,7 +24,7 @@ import reactor.netty.http.server.HttpServerRequest;
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class for creating a {@link URI} from a reactor {@link HttpServerRequest}.
|
* Helper class to create {@link URI} from a Reactor Netty request.
|
||||||
*
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
* @since 6.0.8
|
* @since 6.0.8
|
||||||
|
@ -48,12 +48,16 @@ abstract class ReactorUriHelper {
|
||||||
builder.append(port);
|
builder.append(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reactor Netty has config whether to extract and apply forwarded headers.
|
||||||
|
// We apply the prefix manually as it affects the contextPath too.
|
||||||
|
|
||||||
String prefix = request.forwardedPrefix();
|
String prefix = request.forwardedPrefix();
|
||||||
if (prefix != null && !prefix.isEmpty()) {
|
if (prefix != null && !prefix.isEmpty()) {
|
||||||
builder.append(prefix);
|
builder.append(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
appendRequestUri(request, builder);
|
appendRequestUri(request, builder);
|
||||||
|
|
||||||
return new URI(builder.toString());
|
return new URI(builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ import static org.mockito.BDDMockito.given;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Unit tests for {@link ReactorUriHelper}.
|
||||||
|
*
|
||||||
* @author Arjen Poutsma
|
* @author Arjen Poutsma
|
||||||
*/
|
*/
|
||||||
class ReactorUriHelperTests {
|
class ReactorUriHelperTests {
|
||||||
|
@ -58,14 +60,14 @@ class ReactorUriHelperTests {
|
||||||
" | /",
|
" | /",
|
||||||
"'' | /",
|
"'' | /",
|
||||||
})
|
})
|
||||||
void forwardedPrefix(String prefixHeader, String expectedPath) throws URISyntaxException {
|
void forwardedPrefix(String forwardedPrefixHeader, String expectedPath) throws URISyntaxException {
|
||||||
HttpServerRequest nettyRequest = mock();
|
HttpServerRequest nettyRequest = mock();
|
||||||
|
|
||||||
given(nettyRequest.scheme()).willReturn("https");
|
given(nettyRequest.scheme()).willReturn("https");
|
||||||
given(nettyRequest.hostName()).willReturn("localhost");
|
given(nettyRequest.hostName()).willReturn("localhost");
|
||||||
given(nettyRequest.hostPort()).willReturn(443);
|
given(nettyRequest.hostPort()).willReturn(443);
|
||||||
given(nettyRequest.uri()).willReturn("/");
|
given(nettyRequest.uri()).willReturn("/");
|
||||||
given(nettyRequest.forwardedPrefix()).willReturn(prefixHeader);
|
given(nettyRequest.forwardedPrefix()).willReturn(forwardedPrefixHeader);
|
||||||
|
|
||||||
URI uri = ReactorUriHelper.createUri(nettyRequest);
|
URI uri = ReactorUriHelper.createUri(nettyRequest);
|
||||||
assertThat(uri).hasScheme("https")
|
assertThat(uri).hasScheme("https")
|
||||||
|
@ -75,5 +77,4 @@ class ReactorUriHelperTests {
|
||||||
.hasToString("https://localhost" + expectedPath);
|
.hasToString("https://localhost" + expectedPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue