Browse Source

Adds null check in quoteIfNeeded

fixes gh-337
pull/345/head
Spencer Gibb 7 years ago
parent
commit
96f5c650bf
No known key found for this signature in database
GPG Key ID: 7788A47380690861
  1. 2
      spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java
  2. 23
      spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java

2
spring-cloud-gateway-core/src/main/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilter.java

@ -147,7 +147,7 @@ public class ForwardedHeadersFilter implements HttpHeadersFilter, Ordered { @@ -147,7 +147,7 @@ public class ForwardedHeadersFilter implements HttpHeadersFilter, Ordered {
private String quoteIfNeeded(String s) {
if (s.contains(":")) { //TODO: broaded quote
if (s != null && s.contains(":")) { //TODO: broaded quote
return "\""+s+"\"";
}
return s;

23
spring-cloud-gateway-core/src/test/java/org/springframework/cloud/gateway/filter/headers/ForwardedHeadersFilterTests.java

@ -67,6 +67,29 @@ public class ForwardedHeadersFilterTests { @@ -67,6 +67,29 @@ public class ForwardedHeadersFilterTests {
.containsEntry("for", "\"10.0.0.1:80\"");
}
@Test
public void noHostHeader() throws UnknownHostException {
MockServerHttpRequest request = MockServerHttpRequest
.get("http://localhost/get")
.remoteAddress(new InetSocketAddress(InetAddress.getByName("10.0.0.1"), 80))
.build();
ForwardedHeadersFilter filter = new ForwardedHeadersFilter();
HttpHeaders headers = filter.filter(request.getHeaders(), MockServerWebExchange.from(request));
assertThat(headers.get(FORWARDED_HEADER)).hasSize(1);
List<Forwarded> forwardeds = ForwardedHeadersFilter.parse(headers.get(FORWARDED_HEADER));
assertThat(forwardeds).hasSize(1);
Forwarded forwarded = forwardeds.get(0);
assertThat(forwarded.getValues())
.containsEntry("proto", "http")
.containsEntry("for", "\"10.0.0.1:80\"");
}
@Test
public void forwardedParsedCorrectly() {
String[] valid = new String[] {

Loading…
Cancel
Save