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
2 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ public class ContentTypeUtils {
21
21
private ContentTypeUtils () {}
22
22
23
23
private static final String CHARSET_EQUALS = "charset=" ;
24
+ private static final String SEPARATOR = ";" ;
24
25
25
26
/**
26
27
* Returns true if the request/response with this content type should be captured.
@@ -51,7 +52,13 @@ public static String parseCharset(String contentType) {
51
52
52
53
int indexOfEncoding = indexOfCharset + CHARSET_EQUALS .length ();
53
54
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
+ }
55
62
}
56
63
return null ;
57
64
}
Original file line number Diff line number Diff line change @@ -58,4 +58,15 @@ public void noCharset() {
58
58
Assertions .assertEquals (
59
59
null , ContentTypeUtils .parseCharset ("Content-Type: application/json; charset=" ));
60
60
}
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
+ }
61
72
}
You can’t perform that action at this time.
0 commit comments