arturobernalg commented on code in PR #483:
URL: 
https://github.com/apache/httpcomponents-core/pull/483#discussion_r1773414963


##########
httpcore5/src/main/java/org/apache/hc/core5/http/ContentType.java:
##########
@@ -67,105 +68,125 @@ public final class ContentType implements Serializable {
      */
     private static final String CHARSET = "charset";
 
+    /**
+     * Flag indicating whether the charset is implicit.
+     * <p>
+     * When {@code implicitCharset} is {@code true}, the charset will not be 
explicitly
+     * included in the string representation of this {@link ContentType} 
(i.e., in the {@code toString} method),
+     * unless it is required for the given MIME type.
+     * If {@code implicitCharset} is {@code false}, the charset will always be 
included in the string representation,
+     * unless the MIME type explicitly disallows charset parameters (e.g., 
certain binary or multipart types).
+     * </p>
+     * <p>
+     * This flag is essential for proper handling of content types where the 
charset is either implied by the specification
+     * (e.g., JSON is always UTF-8) or where including a charset is not 
meaningful (e.g., binary types like
+     * {@code application/octet-stream}).
+     * </p>
+     *
+     * @since 5.5
+     */
+    private final boolean implicitCharset;
+
+
     // constants
     public static final ContentType APPLICATION_ATOM_XML = create(
-            "application/atom+xml", StandardCharsets.UTF_8);
+            "application/atom+xml", StandardCharsets.UTF_8, false);
     public static final ContentType APPLICATION_FORM_URLENCODED = create(
-            "application/x-www-form-urlencoded", StandardCharsets.ISO_8859_1);
+            "application/x-www-form-urlencoded", StandardCharsets.ISO_8859_1, 
true);
     public static final ContentType APPLICATION_JSON = create(
-            "application/json", StandardCharsets.UTF_8);
+            "application/json", StandardCharsets.UTF_8, true);
 
     /**
      * Public constant media type for {@code application/x-ndjson}.
      * @since 5.1
      */
     public static final ContentType APPLICATION_NDJSON = create(
-            "application/x-ndjson", StandardCharsets.UTF_8);
+            "application/x-ndjson", StandardCharsets.UTF_8, true);
 
     public static final ContentType APPLICATION_OCTET_STREAM = create(
-            "application/octet-stream", (Charset) null);
+            "application/octet-stream", (Charset) null, true);
     /**
      * Public constant media type for {@code application/pdf}.
      * @since 5.1
      */
     public static final ContentType APPLICATION_PDF = create(
-            "application/pdf", StandardCharsets.UTF_8);
+            "application/pdf", (Charset) null, true);
 
     public static final ContentType APPLICATION_SOAP_XML = create(
-            "application/soap+xml", StandardCharsets.UTF_8);
+            "application/soap+xml", StandardCharsets.UTF_8, false);
     public static final ContentType APPLICATION_SVG_XML = create(
-            "application/svg+xml", StandardCharsets.UTF_8);
+            "application/svg+xml", StandardCharsets.UTF_8, false);
     public static final ContentType APPLICATION_XHTML_XML = create(
-            "application/xhtml+xml", StandardCharsets.UTF_8);
+            "application/xhtml+xml", StandardCharsets.UTF_8, false);
     public static final ContentType APPLICATION_XML = create(
-            "application/xml", StandardCharsets.UTF_8);
+            "application/xml", StandardCharsets.UTF_8, false);
     /**
      * Public constant media type for {@code application/problem+json}.
      * @see <a href="https://tools.ietf.org/html/rfc7807#section-6.1";>Problem 
Details for HTTP APIs, 6.1. application/problem+json</a>
      * @since 5.1
      */
     public static final ContentType APPLICATION_PROBLEM_JSON = create(
-            "application/problem+json", StandardCharsets.UTF_8);
+            "application/problem+json", StandardCharsets.UTF_8, true);
     /**
      * Public constant media type for {@code application/problem+xml}.
      * @see <a href="https://tools.ietf.org/html/rfc7807#section-6.2";>Problem 
Details for HTTP APIs, 6.2. application/problem+xml</a>
      * @since 5.1
      */
     public static final ContentType APPLICATION_PROBLEM_XML = create(
-            "application/problem+xml", StandardCharsets.UTF_8);
+            "application/problem+xml", StandardCharsets.UTF_8, false);
 
     /**
      * Public constant media type for {@code application/rss+xml}.
      * @since 5.1
      */
     public static final ContentType APPLICATION_RSS_XML = create(
-            "application/rss+xml", StandardCharsets.UTF_8);
+            "application/rss+xml", StandardCharsets.UTF_8, false);
 
     public static final ContentType IMAGE_BMP = create(
-            "image/bmp");
+            "image/bmp", (Charset) null, true);
     public static final ContentType IMAGE_GIF = create(
-            "image/gif");
+            "image/gif", (Charset) null, true);
     public static final ContentType IMAGE_JPEG = create(
-            "image/jpeg");
+            "image/jpeg", (Charset) null, true);
     public static final ContentType IMAGE_PNG = create(
-            "image/png");
+            "image/png", (Charset) null, true);
     public static final ContentType IMAGE_SVG = create(
-            "image/svg+xml");
+            "image/svg+xml", (Charset) null, false);

Review Comment:
   cahnged



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@hc.apache.org
For additional commands, e-mail: dev-h...@hc.apache.org

Reply via email to