1
1
/*
2
- * Copyright 2002-2014 the original author or authors.
2
+ * Copyright 2002-2015 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.
@@ -36,15 +36,18 @@ public class ServletUriComponentsBuilderTests {
36
36
37
37
private MockHttpServletRequest request ;
38
38
39
+
39
40
@ Before
40
41
public void setup () {
41
42
this .request = new MockHttpServletRequest ();
42
43
this .request .setScheme ("http" );
43
44
this .request .setServerName ("localhost" );
44
45
this .request .setServerPort (-1 );
46
+ this .request .setRequestURI ("/mvc-showcase" );
45
47
this .request .setContextPath ("/mvc-showcase" );
46
48
}
47
49
50
+
48
51
@ Test
49
52
public void fromRequest () {
50
53
this .request .setRequestURI ("/mvc-showcase/data/param" );
@@ -64,15 +67,15 @@ public void fromRequestEncodedPath() {
64
67
public void fromRequestAtypicalHttpPort () {
65
68
this .request .setServerPort (8080 );
66
69
String result = ServletUriComponentsBuilder .fromRequest (this .request ).build ().toUriString ();
67
- assertEquals ("http://localhost:8080" , result );
70
+ assertEquals ("http://localhost:8080/mvc-showcase " , result );
68
71
}
69
72
70
73
@ Test
71
74
public void fromRequestAtypicalHttpsPort () {
72
75
this .request .setScheme ("https" );
73
76
this .request .setServerPort (9043 );
74
77
String result = ServletUriComponentsBuilder .fromRequest (this .request ).build ().toUriString ();
75
- assertEquals ("https://localhost:9043" , result );
78
+ assertEquals ("https://localhost:9043/mvc-showcase " , result );
76
79
}
77
80
78
81
@ Test
@@ -150,6 +153,19 @@ public void fromRequestWithForwardedHostWithForwardedScheme() {
150
153
assertEquals ("should have used the default port of the forwarded request" , -1 , result .getPort ());
151
154
}
152
155
156
+ // SPR-12771
157
+
158
+ @ Test
159
+ public void fromRequestWithForwardedProtoAndDefaultPort () {
160
+ this .request .addHeader ("X-Forwarded-Proto" , "https" );
161
+ this .request .addHeader ("X-Forwarded-Host" , "84.198.58.199" );
162
+ this .request .addHeader ("X-Forwarded-Port" , "443" );
163
+ this .request .setServerPort (80 );
164
+ UriComponents result = ServletUriComponentsBuilder .fromRequest (this .request ).build ();
165
+
166
+ assertEquals ("https://84.198.58.199/mvc-showcase" , result .toString ());
167
+ }
168
+
153
169
@ Test
154
170
public void fromRequestWithForwardedPrefix () {
155
171
this .request .setRequestURI ("/bar" );
0 commit comments