1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -40,8 +40,7 @@ public class ForwardedHeaderTransformerTests {
40
40
41
41
42
42
@ Test
43
- public void removeOnly () {
44
-
43
+ void removeOnly () {
45
44
this .requestMutator .setRemoveOnly (true );
46
45
47
46
HttpHeaders headers = new HttpHeaders ();
@@ -57,7 +56,7 @@ public void removeOnly() {
57
56
}
58
57
59
58
@ Test
60
- public void xForwardedHeaders () throws Exception {
59
+ void xForwardedHeaders () throws Exception {
61
60
HttpHeaders headers = new HttpHeaders ();
62
61
headers .add ("X-Forwarded-Host" , "84.198.58.199" );
63
62
headers .add ("X-Forwarded-Port" , "443" );
@@ -70,7 +69,7 @@ public void xForwardedHeaders() throws Exception {
70
69
}
71
70
72
71
@ Test
73
- public void forwardedHeader () throws Exception {
72
+ void forwardedHeader () throws Exception {
74
73
HttpHeaders headers = new HttpHeaders ();
75
74
headers .add ("Forwarded" , "host=84.198.58.199;proto=https" );
76
75
ServerHttpRequest request = this .requestMutator .apply (getRequest (headers ));
@@ -80,7 +79,7 @@ public void forwardedHeader() throws Exception {
80
79
}
81
80
82
81
@ Test
83
- public void xForwardedPrefix () throws Exception {
82
+ void xForwardedPrefix () throws Exception {
84
83
HttpHeaders headers = new HttpHeaders ();
85
84
headers .add ("X-Forwarded-Prefix" , "/prefix" );
86
85
ServerHttpRequest request = this .requestMutator .apply (getRequest (headers ));
@@ -91,7 +90,7 @@ public void xForwardedPrefix() throws Exception {
91
90
}
92
91
93
92
@ Test // gh-23305
94
- public void xForwardedPrefixShouldNotLeadToDecodedPath () throws Exception {
93
+ void xForwardedPrefixShouldNotLeadToDecodedPath () throws Exception {
95
94
HttpHeaders headers = new HttpHeaders ();
96
95
headers .add ("X-Forwarded-Prefix" , "/prefix" );
97
96
ServerHttpRequest request = MockServerHttpRequest
@@ -107,7 +106,7 @@ public void xForwardedPrefixShouldNotLeadToDecodedPath() throws Exception {
107
106
}
108
107
109
108
@ Test
110
- public void xForwardedPrefixTrailingSlash () throws Exception {
109
+ void xForwardedPrefixTrailingSlash () throws Exception {
111
110
HttpHeaders headers = new HttpHeaders ();
112
111
headers .add ("X-Forwarded-Prefix" , "/prefix////" );
113
112
ServerHttpRequest request = this .requestMutator .apply (getRequest (headers ));
@@ -118,7 +117,7 @@ public void xForwardedPrefixTrailingSlash() throws Exception {
118
117
}
119
118
120
119
@ Test // SPR-17525
121
- public void shouldNotDoubleEncode () throws Exception {
120
+ void shouldNotDoubleEncode () throws Exception {
122
121
HttpHeaders headers = new HttpHeaders ();
123
122
headers .add ("Forwarded" , "host=84.198.58.199;proto=https" );
124
123
@@ -133,6 +132,28 @@ public void shouldNotDoubleEncode() throws Exception {
133
132
assertForwardedHeadersRemoved (request );
134
133
}
135
134
135
+ @ Test
136
+ void shouldConcatenatePrefixes () throws Exception {
137
+ HttpHeaders headers = new HttpHeaders ();
138
+ headers .add ("X-Forwarded-Prefix" , "/first,/second" );
139
+ ServerHttpRequest request = this .requestMutator .apply (getRequest (headers ));
140
+
141
+ assertThat (request .getURI ()).isEqualTo (new URI ("https://example.com/first/second/path" ));
142
+ assertThat (request .getPath ().value ()).isEqualTo ("/first/second/path" );
143
+ assertForwardedHeadersRemoved (request );
144
+ }
145
+
146
+ @ Test
147
+ void shouldConcatenatePrefixesWithTrailingSlashes () throws Exception {
148
+ HttpHeaders headers = new HttpHeaders ();
149
+ headers .add ("X-Forwarded-Prefix" , "/first/,/second//" );
150
+ ServerHttpRequest request = this .requestMutator .apply (getRequest (headers ));
151
+
152
+ assertThat (request .getURI ()).isEqualTo (new URI ("https://example.com/first/second/path" ));
153
+ assertThat (request .getPath ().value ()).isEqualTo ("/first/second/path" );
154
+ assertForwardedHeadersRemoved (request );
155
+ }
156
+
136
157
137
158
private MockServerHttpRequest getRequest (HttpHeaders headers ) {
138
159
return MockServerHttpRequest .get (BASE_URL ).headers (headers ).build ();
0 commit comments