|
13 | 13 | package com.amazonaws.serverless.proxy.internal.servlet; |
14 | 14 |
|
15 | 15 | import com.amazonaws.serverless.proxy.RequestReader; |
16 | | -import com.amazonaws.serverless.proxy.internal.LambdaContainerHandler; |
17 | 16 | import com.amazonaws.serverless.proxy.internal.SecurityUtils; |
18 | 17 | import com.amazonaws.serverless.proxy.model.AwsProxyRequestContext; |
19 | 18 | import com.amazonaws.serverless.proxy.model.ContainerConfig; |
20 | 19 | import com.amazonaws.serverless.proxy.model.MultiValuedTreeMap; |
21 | 20 | import com.amazonaws.services.lambda.runtime.Context; |
22 | 21 |
|
23 | | -import com.fasterxml.jackson.core.JsonProcessingException; |
24 | | -import org.apache.http.HeaderElement; |
25 | 22 | import org.apache.http.message.BasicHeaderValueParser; |
26 | | -import org.apache.http.message.ParserCursor; |
27 | | -import org.apache.http.util.CharArrayBuffer; |
28 | 23 | import org.slf4j.Logger; |
29 | 24 | import org.slf4j.LoggerFactory; |
30 | 25 |
|
@@ -376,31 +371,44 @@ protected List<HeaderValue> parseHeaderValue(String headerValue, String valueSep |
376 | 371 | newValue.setRawValue(v); |
377 | 372 |
|
378 | 373 | for (String q : curValue.split(qualifierSeparator)) { |
379 | | - // contains key/value pairs and it's not a base64-encoded value. |
380 | | - if (q.contains(HEADER_KEY_VALUE_SEPARATOR) && !q.trim().endsWith("==")) { |
381 | | - String[] kv = q.split(HEADER_KEY_VALUE_SEPARATOR); |
382 | | - String key = kv[0].trim(); |
383 | | - String val = null; |
384 | | - if (kv.length > 1) { |
385 | | - val = kv[1].trim(); |
| 374 | + |
| 375 | + String[] kv = q.split(HEADER_KEY_VALUE_SEPARATOR, 2); |
| 376 | + String key = null; |
| 377 | + String val = null; |
| 378 | + // no separator, set the value only |
| 379 | + if (kv.length == 1) { |
| 380 | + val = q.trim(); |
| 381 | + } |
| 382 | + // we have a separator |
| 383 | + if (kv.length == 2) { |
| 384 | + // if the length of the value is 0 we assume that we are looking at a |
| 385 | + // base64 encoded value with padding so we just set the value. This is because |
| 386 | + // we assume that empty values in a key/value pair will contain at least a white space |
| 387 | + if (kv[1].length() == 0) { |
| 388 | + val = q.trim(); |
386 | 389 | } |
387 | | - // TODO: Should we concatenate the rest of the values? |
388 | | - if (newValue.getValue() == null) { |
389 | | - newValue.setKey(key); |
390 | | - newValue.setValue(val); |
391 | | - } else { |
392 | | - // special case for quality q= |
393 | | - if ("q".equals(key)) { |
394 | | - curPreference = Float.parseFloat(val); |
395 | | - } else { |
396 | | - newValue.addAttribute(key, val); |
397 | | - } |
| 390 | + // this was a base64 string with an additional = for padding, set the value only |
| 391 | + if ("=".equals(kv[1].trim())) { |
| 392 | + val = q.trim(); |
| 393 | + } else { // it's a proper key/value set both |
| 394 | + key = kv[0].trim(); |
| 395 | + val = ("".equals(kv[1].trim()) ? null : kv[1].trim()); |
398 | 396 | } |
| 397 | + } |
| 398 | + |
| 399 | + if (newValue.getValue() == null) { |
| 400 | + newValue.setKey(key); |
| 401 | + newValue.setValue(val); |
399 | 402 | } else { |
400 | | - newValue.setValue(q.trim()); |
| 403 | + // special case for quality q= |
| 404 | + if ("q".equals(key)) { |
| 405 | + curPreference = Float.parseFloat(val); |
| 406 | + } else { |
| 407 | + newValue.addAttribute(key, val); |
| 408 | + } |
401 | 409 | } |
402 | | - newValue.setPriority(curPreference); |
403 | 410 | } |
| 411 | + newValue.setPriority(curPreference); |
404 | 412 | values.add(newValue); |
405 | 413 | } |
406 | 414 |
|
@@ -428,7 +436,6 @@ protected String decodeRequestPath(String requestPath, ContainerConfig config) { |
428 | 436 |
|
429 | 437 | } |
430 | 438 |
|
431 | | - |
432 | 439 | /** |
433 | 440 | * Class that represents a header value. |
434 | 441 | */ |
|
0 commit comments