File tree Expand file tree Collapse file tree 2 files changed +19
-1
lines changed
main/java/org/hypertrace/agent/core/instrumentation/utils
test/java/org/hypertrace/agent/core/instrumentation/utils Expand file tree Collapse file tree 2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public class ContentTypeUtils {
2121 private ContentTypeUtils () {}
2222
2323 private static final String CHARSET_EQUALS = "charset=" ;
24+ private static final String SEPARATOR = ";" ;
2425
2526 /**
2627 * Returns true if the request/response with this content type should be captured.
@@ -51,7 +52,13 @@ public static String parseCharset(String contentType) {
5152
5253 int indexOfEncoding = indexOfCharset + CHARSET_EQUALS .length ();
5354 if (indexOfEncoding < contentType .length ()) {
54- return contentType .substring (indexOfEncoding , contentType .length ());
55+ String substring = contentType .substring (indexOfEncoding , contentType .length ());
56+ int semicolonIndex = substring .indexOf (SEPARATOR );
57+ if (semicolonIndex == -1 ) {
58+ return substring ;
59+ } else {
60+ return substring .substring (0 , semicolonIndex );
61+ }
5562 }
5663 return null ;
5764 }
Original file line number Diff line number Diff line change @@ -58,4 +58,15 @@ public void noCharset() {
5858 Assertions .assertEquals (
5959 null , ContentTypeUtils .parseCharset ("Content-Type: application/json; charset=" ));
6060 }
61+
62+ /**
63+ * Charsets can contain a "quality factor" per <a
64+ * href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.2"></a>
65+ */
66+ @ Test
67+ void charsetWithCharsetQualityFactor () {
68+ Assertions .assertEquals (
69+ "utf-8" ,
70+ ContentTypeUtils .parseCharset ("Content-Type: application/json; charset=utf-8;q=.2" ));
71+ }
6172}
You can’t perform that action at this time.
0 commit comments