|
21 | 21 | import feign.template.UriTemplate;
|
22 | 22 | import feign.template.UriUtils;
|
23 | 23 | import java.io.Serializable;
|
| 24 | +import java.net.URI; |
24 | 25 | import java.nio.charset.Charset;
|
25 | 26 | import java.util.*;
|
26 | 27 | import java.util.AbstractMap.SimpleImmutableEntry;
|
@@ -400,7 +401,10 @@ public RequestTemplate uri(String uri, boolean append) {
|
400 | 401 |
|
401 | 402 | if (uri == null) {
|
402 | 403 | uri = "/";
|
403 |
| - } else if ((!uri.isEmpty() && !uri.startsWith("/") && !uri.startsWith("{"))) { |
| 404 | + } else if ((!uri.isEmpty() |
| 405 | + && !uri.startsWith("/") |
| 406 | + && !uri.startsWith("{") |
| 407 | + && !uri.startsWith("?"))) { |
404 | 408 | /* if the start of the url is a literal, it must begin with a slash. */
|
405 | 409 | uri = "/" + uri;
|
406 | 410 | }
|
@@ -448,20 +452,23 @@ public RequestTemplate target(String target) {
|
448 | 452 | if (target.endsWith("/")) {
|
449 | 453 | target = target.substring(0, target.length() - 1);
|
450 | 454 | }
|
451 |
| - |
452 |
| - /* no query strings allowed */ |
453 |
| - Matcher queryStringMatcher = QUERY_STRING_PATTERN.matcher(target); |
454 |
| - if (queryStringMatcher.find()) { |
455 |
| - /* |
456 |
| - * target has a query string, we need to make sure that they are recorded as queries |
457 |
| - */ |
458 |
| - int queryStart = queryStringMatcher.start(); |
459 |
| - this.extractQueryTemplates(target.substring(queryStart + 1), true); |
| 455 | + try { |
| 456 | + /* parse the target */ |
| 457 | + URI targetUri = URI.create(target); |
| 458 | + |
| 459 | + if (Util.isNotBlank(targetUri.getRawQuery())) { |
| 460 | + /* |
| 461 | + * target has a query string, we need to make sure that they are recorded as queries |
| 462 | + */ |
| 463 | + this.extractQueryTemplates(targetUri.getRawQuery(), true); |
| 464 | + } |
460 | 465 |
|
461 | 466 | /* strip the query string */
|
462 |
| - target = target.substring(0, queryStart); |
| 467 | + this.target = targetUri.getScheme() + "://" + targetUri.getAuthority() + targetUri.getPath(); |
| 468 | + } catch (IllegalArgumentException iae) { |
| 469 | + /* the uri provided is not a valid one, we can't continue */ |
| 470 | + throw new IllegalArgumentException("Target is not a valid URI.", iae); |
463 | 471 | }
|
464 |
| - this.target = target; |
465 | 472 | return this;
|
466 | 473 | }
|
467 | 474 |
|
|
0 commit comments