@@ -63,6 +63,9 @@ protected ServletUriComponentsBuilder(ServletUriComponentsBuilder other) {
63
63
this .originalPath = other .originalPath ;
64
64
}
65
65
66
+
67
+ // Factory methods based on a HttpServletRequest
68
+
66
69
/**
67
70
* Prepare a builder from the host, port, scheme, and context path of the
68
71
* given HttpServletRequest.
@@ -76,7 +79,6 @@ public static ServletUriComponentsBuilder fromContextPath(HttpServletRequest req
76
79
/**
77
80
* Prepare a builder from the host, port, scheme, context path, and
78
81
* servlet mapping of the given HttpServletRequest.
79
- *
80
82
* <p>If the servlet is mapped by name, e.g. {@code "/main/*"}, the path
81
83
* will end with "/main". If the servlet is mapped otherwise, e.g.
82
84
* {@code "/"} or {@code "*.do"}, the result will be the same as
@@ -124,17 +126,12 @@ private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest re
124
126
ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder ();
125
127
builder .scheme (scheme );
126
128
builder .host (host );
127
- if (scheme . equals ("http" ) && port != 80 || scheme . equals ("https" ) && port != 443 ) {
129
+ if (("http" . equals ( scheme ) && port != 80 ) || ("https" . equals ( scheme ) && port != 443 ) ) {
128
130
builder .port (port );
129
131
}
130
132
return builder ;
131
133
}
132
134
133
- private void initPath (String path ) {
134
- this .originalPath = path ;
135
- replacePath (path );
136
- }
137
-
138
135
private static String prependForwardedPrefix (HttpServletRequest request , String path ) {
139
136
String prefix = request .getHeader ("X-Forwarded-Prefix" );
140
137
if (StringUtils .hasText (prefix )) {
@@ -178,9 +175,8 @@ public static ServletUriComponentsBuilder fromCurrentRequest() {
178
175
return fromRequest (getCurrentRequest ());
179
176
}
180
177
181
-
182
178
/**
183
- * Get the request through {@link RequestContextHolder}.
179
+ * Obtain current request through {@link RequestContextHolder}.
184
180
*/
185
181
protected static HttpServletRequest getCurrentRequest () {
186
182
RequestAttributes requestAttributes = RequestContextHolder .getRequestAttributes ();
@@ -191,12 +187,17 @@ protected static HttpServletRequest getCurrentRequest() {
191
187
return servletRequest ;
192
188
}
193
189
190
+
191
+ private void initPath (String path ) {
192
+ this .originalPath = path ;
193
+ replacePath (path );
194
+ }
195
+
194
196
/**
195
197
* Remove any path extension from the {@link HttpServletRequest#getRequestURI()
196
198
* requestURI}. This method must be invoked before any calls to {@link #path(String)}
197
199
* or {@link #pathSegment(String...)}.
198
200
* <pre>
199
- *
200
201
* GET http://foo.com/rest/books/6.json
201
202
*
202
203
* ServletUriComponentsBuilder builder = ServletUriComponentsBuilder.fromRequestUri(this.request);
0 commit comments