|
38 | 38 | import java.util.LinkedHashMap; |
39 | 39 | import java.util.List; |
40 | 40 | import java.util.Map; |
41 | | -import java.util.concurrent.atomic.AtomicReference; |
42 | 41 |
|
43 | 42 | import org.apache.hc.core5.annotation.Contract; |
44 | 43 | import org.apache.hc.core5.annotation.ThreadingBehavior; |
| 44 | +import org.apache.hc.core5.http.message.BasicHeaderValueParser; |
45 | 45 | import org.apache.hc.core5.http.message.BasicNameValuePair; |
46 | 46 | import org.apache.hc.core5.http.message.MessageSupport; |
47 | 47 | import org.apache.hc.core5.http.message.ParserCursor; |
@@ -434,15 +434,31 @@ private static ContentType parse(final CharSequence s, final boolean strict) thr |
434 | 434 | return null; |
435 | 435 | } |
436 | 436 | final ParserCursor cursor = new ParserCursor(0, s.length()); |
437 | | - final AtomicReference<HeaderElement> firstElementRef = new AtomicReference<>(); |
438 | | - MessageSupport.parseElements(s, cursor, e -> firstElementRef.compareAndSet(null, e)); |
439 | | - final HeaderElement element = firstElementRef.get(); |
| 437 | + return parse(s, cursor, strict); |
| 438 | + } |
| 439 | + |
| 440 | + private static ContentType parse(final CharSequence s, final ParserCursor cursor, final boolean strict) throws UnsupportedCharsetException { |
| 441 | + final HeaderElement element = BasicHeaderValueParser.INSTANCE.parseHeaderElement(s, cursor); |
440 | 442 | if (element != null) { |
441 | 443 | return create(element, strict); |
442 | 444 | } |
443 | 445 | return null; |
444 | 446 | } |
445 | 447 |
|
| 448 | + /** |
| 449 | + * @since 5.5 |
| 450 | + */ |
| 451 | + public static ContentType parse(final CharSequence s, final ParserCursor cursor) throws UnsupportedCharsetException { |
| 452 | + return parse(s, cursor, true); |
| 453 | + } |
| 454 | + |
| 455 | + /** |
| 456 | + * @since 5.5 |
| 457 | + */ |
| 458 | + public static ContentType parseLenient(final CharSequence s, final ParserCursor cursor) throws UnsupportedCharsetException { |
| 459 | + return parse(s, cursor, false); |
| 460 | + } |
| 461 | + |
446 | 462 | /** |
447 | 463 | * Returns {@code Content-Type} for the given MIME type. |
448 | 464 | * |
|
0 commit comments