Changeset 6849 in josm for trunk/src/oauth/signpost/http
- Timestamp:
- 2014-02-13T21:10:18+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/oauth/signpost/http/HttpParameters.java
r4231 r6849 87 87 */ 88 88 public String put(String key, String value, boolean percentEncode) { 89 SortedSet<String> values = wrappedMap.get(key); 90 if (values == null) { 91 values = new TreeSet<String>(); 92 wrappedMap.put(percentEncode ? OAuth.percentEncode(key) : key, values); 93 } 94 if (value != null) { 95 value = percentEncode ? OAuth.percentEncode(value) : value; 96 values.add(value); 97 } 98 99 return value; 100 } 89 // fix contributed by Bjorn Roche - key should be encoded before wrappedMap.get 90 key = percentEncode ? OAuth.percentEncode(key) : key; 91 SortedSet<String> values = wrappedMap.get(key); 92 if (values == null) { 93 values = new TreeSet<String>(); 94 wrappedMap.put( key, values); 95 } 96 if (value != null) { 97 value = percentEncode ? OAuth.percentEncode(value) : value; 98 values.add(value); 99 } 100 101 return value; 102 } 101 103 102 104 /** … … 200 202 */ 201 203 public String getAsQueryString(Object key) { 204 return getAsQueryString(key, true); 205 } 206 207 /** 208 * Concatenates all values for the given key to a list of key/value pairs 209 * suitable for use in a URL query string. 210 * 211 * @param key 212 * the parameter name 213 * @param percentEncode 214 * whether key should be percent encoded before being 215 * used with the map 216 * @return the query string 217 */ 218 public String getAsQueryString(Object key, boolean percentEncode) { 219 // fix contributed by Stjepan Rajko - we need the percentEncode parameter 220 // because some places (like SignatureBaseString.normalizeRequestParameters) 221 // need to supply the parameter percent encoded 222 202 223 StringBuilder sb = new StringBuilder(); 203 key = OAuth.percentEncode((String) key); 224 if(percentEncode) 225 key = OAuth.percentEncode((String) key); 204 226 Set<String> values = wrappedMap.get(key); 205 227 if (values == null) { … … 215 237 return sb.toString(); 216 238 } 217 239 218 240 public String getAsHeaderElement(String key) { 219 241 String value = getFirst(key); … … 265 287 } 266 288 267 public Set< java.util.Map.Entry<String, SortedSet<String>>> entrySet() {289 public Set<Entry<String, SortedSet<String>>> entrySet() { 268 290 return wrappedMap.entrySet(); 269 291 } 292 293 public HttpParameters getOAuthParameters() { 294 HttpParameters oauthParams = new HttpParameters(); 295 296 for (Entry<String, SortedSet<String>> param : this.entrySet()) { 297 String key = param.getKey(); 298 if (key.startsWith("oauth_") || key.startsWith("x_oauth_")) { 299 oauthParams.put(key, param.getValue()); 300 } 301 } 302 303 return oauthParams; 304 } 270 305 }
Note:
See TracChangeset
for help on using the changeset viewer.