ok2c commented on code in PR #564:
URL: 
https://github.com/apache/httpcomponents-core/pull/564#discussion_r2398537396


##########
httpcore5/src/main/java/org/apache/hc/core5/http/message/AlpnHeader.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.message;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Tokenizer;
+
+/**
+ * Codec for the HTTP {@code ALPN} header field (RFC 7639).
+ *
+ * <h2>Canonical encoding (RFC 7639 §2.2)</h2>
+ * Each protocol ID is encoded as:
+ * <ul>
+ *   <li>HTTP {@code tchar} bytes remain literal <em>except</em> {@code '%'}, 
which MUST be percent-encoded.</li>
+ *   <li>All other bytes MUST be percent-encoded as {@code %HH} with 
<strong>uppercase</strong> hex.</li>
+ *   <li>UTF-8 is used to convert characters to bytes before encoding.</li>
+ * </ul>
+ *
+ * <h2>List formatting</h2>
+ * The header value is a comma-separated list of encoded protocol IDs.
+ * OWS around commas is tolerated on parse and normalized on format.
+ *
+ * <h2>Parsing</h2>
+ * Liberal parsing: accepts lowercase hex in {@code %hh}; leaves malformed or 
incomplete
+ * percent sequences literal. Quoted values are not produced by this codec and 
are not required
+ * by the spec (ALPN IDs are tokens).
+ *
+ * <p><strong>Thread-safety:</strong> This class is immutable and 
thread-safe.</p>
+ *
+ * @since 5.4
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class AlpnHeader {
+
+    private static final char[] HEXADECIMAL = "0123456789ABCDEF".toCharArray();
+
+    private AlpnHeader() {
+    }
+
+    /**
+     * Formats a list of raw ALPN protocol IDs into a single {@code ALPN} 
header value.
+     *
+     * @param protocolIds e.g. {@code ["h2","http/1.1"]}
+     * @return e.g. {@code "h2, http%2F1.1"}
+     * @since 5.4
+     */
+    public static String formatValue(final List<String> protocolIds) {
+        Args.notEmpty(protocolIds, "protocolIds");
+        final StringBuilder sb = new StringBuilder();
+        boolean first = true;
+        for (final String id : protocolIds) {
+            if (!first) {
+                sb.append(", ");
+            }
+            sb.append(encodeId(id));
+            first = false;
+        }
+        return sb.toString();
+    }
+
+    /**
+     * Parses an {@code ALPN} header value into decoded protocol IDs.
+     * Uses {@link Tokenizer} to handle OWS and commas without intermediate 
copies.
+     *
+     * @param value header value (may be {@code null} or empty)
+     * @return decoded IDs; never {@code null}
+     * @since 5.4
+     */
+    public static List<String> parseValue(final String value) {

Review Comment:
   @arturobernalg Use `MessageSupport#parseElementList` or 
`MessageSupport#parseTokens` here.



##########
httpcore5/src/main/java/org/apache/hc/core5/http/message/AlpnHeader.java:
##########
@@ -0,0 +1,230 @@
+/*
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.hc.core5.http.message;
+
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.hc.core5.annotation.Contract;
+import org.apache.hc.core5.annotation.ThreadingBehavior;
+import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.Tokenizer;
+
+/**
+ * Codec for the HTTP {@code ALPN} header field (RFC 7639).
+ *
+ * <h2>Canonical encoding (RFC 7639 §2.2)</h2>
+ * Each protocol ID is encoded as:
+ * <ul>
+ *   <li>HTTP {@code tchar} bytes remain literal <em>except</em> {@code '%'}, 
which MUST be percent-encoded.</li>
+ *   <li>All other bytes MUST be percent-encoded as {@code %HH} with 
<strong>uppercase</strong> hex.</li>
+ *   <li>UTF-8 is used to convert characters to bytes before encoding.</li>
+ * </ul>
+ *
+ * <h2>List formatting</h2>
+ * The header value is a comma-separated list of encoded protocol IDs.
+ * OWS around commas is tolerated on parse and normalized on format.
+ *
+ * <h2>Parsing</h2>
+ * Liberal parsing: accepts lowercase hex in {@code %hh}; leaves malformed or 
incomplete
+ * percent sequences literal. Quoted values are not produced by this codec and 
are not required
+ * by the spec (ALPN IDs are tokens).
+ *
+ * <p><strong>Thread-safety:</strong> This class is immutable and 
thread-safe.</p>
+ *
+ * @since 5.4
+ */
+@Contract(threading = ThreadingBehavior.IMMUTABLE)
+public final class AlpnHeader {

Review Comment:
   @arturobernalg It is going to be a support class used in client, right? 
Maybe it should be called `AlpnHeaderSupport` and be ` @Internal`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to