11/**
2- * Copyright 2012-2019 The Feign Authors
2+ * Copyright 2012-2020 The Feign Authors
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
55 * in compliance with the License. You may obtain a copy of the License at
1313 */
1414package feign .template ;
1515
16+ import feign .CollectionFormat ;
17+ import feign .Util ;
18+ import feign .template .Template .EncodingOptions ;
19+ import feign .template .Template .ExpansionOptions ;
1620import java .nio .charset .Charset ;
1721import java .nio .charset .StandardCharsets ;
1822import java .util .ArrayList ;
2428import java .util .concurrent .CopyOnWriteArrayList ;
2529import java .util .stream .Collectors ;
2630import java .util .stream .StreamSupport ;
27- import feign .CollectionFormat ;
28- import feign .Util ;
29- import feign .template .Template .EncodingOptions ;
30- import feign .template .Template .ExpansionOptions ;
3131
3232/**
3333 * Template for a Query String parameter.
@@ -49,7 +49,14 @@ public final class QueryTemplate {
4949 * @return a QueryTemplate.
5050 */
5151 public static QueryTemplate create (String name , Iterable <String > values , Charset charset ) {
52- return create (name , values , charset , CollectionFormat .EXPLODED );
52+ return create (name , values , charset , CollectionFormat .EXPLODED , true );
53+ }
54+
55+ public static QueryTemplate create (String name ,
56+ Iterable <String > values ,
57+ Charset charset ,
58+ CollectionFormat collectionFormat ) {
59+ return create (name , values , charset , collectionFormat , true );
5360 }
5461
5562 /**
@@ -59,12 +66,14 @@ public static QueryTemplate create(String name, Iterable<String> values, Charset
5966 * @param values in the template.
6067 * @param charset for the template.
6168 * @param collectionFormat to use.
69+ * @param decodeSlash if slash characters should be decoded
6270 * @return a QueryTemplate
6371 */
6472 public static QueryTemplate create (String name ,
6573 Iterable <String > values ,
6674 Charset charset ,
67- CollectionFormat collectionFormat ) {
75+ CollectionFormat collectionFormat ,
76+ boolean decodeSlash ) {
6877 if (Util .isBlank (name )) {
6978 throw new IllegalArgumentException ("name is required." );
7079 }
@@ -78,7 +87,7 @@ public static QueryTemplate create(String name,
7887 .filter (Util ::isNotBlank )
7988 .collect (Collectors .toList ());
8089
81- return new QueryTemplate (name , remaining , charset , collectionFormat );
90+ return new QueryTemplate (name , remaining , charset , collectionFormat , decodeSlash );
8291 }
8392
8493 /**
@@ -90,13 +99,14 @@ public static QueryTemplate create(String name,
9099 */
91100 public static QueryTemplate append (QueryTemplate queryTemplate ,
92101 Iterable <String > values ,
93- CollectionFormat collectionFormat ) {
102+ CollectionFormat collectionFormat ,
103+ boolean decodeSlash ) {
94104 List <String > queryValues = new ArrayList <>(queryTemplate .getValues ());
95105 queryValues .addAll (StreamSupport .stream (values .spliterator (), false )
96106 .filter (Util ::isNotBlank )
97107 .collect (Collectors .toList ()));
98108 return create (queryTemplate .getName (), queryValues , StandardCharsets .UTF_8 ,
99- collectionFormat );
109+ collectionFormat , decodeSlash );
100110 }
101111
102112 /**
@@ -110,10 +120,11 @@ private QueryTemplate(
110120 String name ,
111121 Iterable <String > values ,
112122 Charset charset ,
113- CollectionFormat collectionFormat ) {
123+ CollectionFormat collectionFormat ,
124+ boolean decodeSlash ) {
114125 this .values = new CopyOnWriteArrayList <>();
115126 this .name = new Template (name , ExpansionOptions .ALLOW_UNRESOLVED , EncodingOptions .REQUIRED ,
116- false , charset );
127+ ! decodeSlash , charset );
117128 this .collectionFormat = collectionFormat ;
118129
119130 /* parse each value into a template chunk for resolution later */
@@ -128,7 +139,7 @@ private QueryTemplate(
128139 value ,
129140 ExpansionOptions .REQUIRED ,
130141 EncodingOptions .REQUIRED ,
131- false ,
142+ ! decodeSlash ,
132143 charset ));
133144 }
134145
0 commit comments