@@ -71,34 +71,8 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
71
71
72
72
private static final Pattern QUERY_PARAM_PATTERN = Pattern .compile ("([^&=]+)(=?)([^&]+)?" );
73
73
74
- private static final String SCHEME_PATTERN = "([^:/?#\\ \\ ]+):" ;
75
-
76
- private static final String USERINFO_PATTERN = "([^/?#\\ \\ ]*)" ;
77
-
78
- private static final String HOST_IPV4_PATTERN = "[^/?#:\\ \\ ]*" ;
79
-
80
- private static final String HOST_IPV6_PATTERN = "\\ [[\\ p{XDigit}:.]*[%\\ p{Alnum}]*]" ;
81
-
82
- private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")" ;
83
-
84
- private static final String PORT_PATTERN = "(\\ {[^}]+\\ }?|[^/?#\\ \\ ]*)" ;
85
-
86
- private static final String PATH_PATTERN = "([^?#]*)" ;
87
-
88
- private static final String QUERY_PATTERN = "([^#]*)" ;
89
-
90
- private static final String LAST_PATTERN = "(.*)" ;
91
-
92
- // Regex patterns that matches URIs. See RFC 3986, appendix B
93
- private static final Pattern URI_PATTERN = Pattern .compile (
94
- "^(" + SCHEME_PATTERN + ")?" + "(//(" + USERINFO_PATTERN + "@)?" + HOST_PATTERN + "(:" + PORT_PATTERN +
95
- ")?" + ")?" + PATH_PATTERN + "(\\ ?" + QUERY_PATTERN + ")?" + "(#" + LAST_PATTERN + ")?" );
96
-
97
74
private static final Object [] EMPTY_VALUES = new Object [0 ];
98
75
99
- private static final WhatWgUrlParser .UrlRecord EMPTY_URL_RECORD = new WhatWgUrlParser .UrlRecord ();
100
-
101
-
102
76
@ Nullable
103
77
private String scheme ;
104
78
@@ -237,7 +211,8 @@ public static UriComponentsBuilder fromUriString(String uri, ParserType parserTy
237
211
yield builder .rfcUriRecord (record );
238
212
}
239
213
case WHAT_WG -> {
240
- WhatWgUrlParser .UrlRecord record = WhatWgUrlParser .parse (uri , EMPTY_URL_RECORD , null , null );
214
+ WhatWgUrlParser .UrlRecord record =
215
+ WhatWgUrlParser .parse (uri , WhatWgUrlParser .EMPTY_RECORD , null , null );
241
216
yield builder .whatWgUrlRecord (record );
242
217
}
243
218
};
@@ -293,27 +268,12 @@ public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
293
268
/**
294
269
* Create an instance by parsing the "Origin" header of an HTTP request.
295
270
* @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454</a>
271
+ * @deprecated in favor of {@link UriComponentsBuilder#fromUriString(String)};
272
+ * to be removed in 7.0
296
273
*/
274
+ @ Deprecated (since = "6.2" , forRemoval = true )
297
275
public static UriComponentsBuilder fromOriginHeader (String origin ) {
298
- Matcher matcher = URI_PATTERN .matcher (origin );
299
- if (matcher .matches ()) {
300
- UriComponentsBuilder builder = new UriComponentsBuilder ();
301
- String scheme = matcher .group (2 );
302
- String host = matcher .group (6 );
303
- String port = matcher .group (8 );
304
- if (StringUtils .hasLength (scheme )) {
305
- builder .scheme (scheme );
306
- }
307
- builder .host (host );
308
- if (StringUtils .hasLength (port )) {
309
- builder .port (port );
310
- }
311
- checkSchemeAndHost (origin , scheme , host );
312
- return builder ;
313
- }
314
- else {
315
- throw new IllegalArgumentException ("[" + origin + "] is not a valid \" Origin\" header value" );
316
- }
276
+ return fromUriString (origin );
317
277
}
318
278
319
279
0 commit comments