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


##########
httpcore5-h2/src/main/java/org/apache/hc/core5/http2/protocol/H2RequestConformance.java:
##########
@@ -75,20 +76,37 @@ public H2RequestConformance() {
     public void process(final HttpRequest request, final EntityDetails entity, 
final HttpContext localContext)
             throws HttpException, IOException {
         Args.notNull(request, "HTTP request");
+
+        boolean validateTe = false;
         for (int i = 0; i < illegalHeaderNames.length; i++) {
             final String headerName = illegalHeaderNames[i];
-            final Header header = request.getFirstHeader(headerName);
-            if (header != null) {
-                if (headerName.equalsIgnoreCase(HttpHeaders.TE)) {
-                    final String value = header.getValue();
-                    if (!"trailers".equalsIgnoreCase(value)) {
-                        throw new ProtocolException("Header '%s: %s' is 
illegal for HTTP/2 messages", HttpHeaders.TE, value);
-                    }
-                } else {
-                    throw new ProtocolException("Header '%s' is illegal for 
HTTP/2 messages", headerName);
-                }
+            if (HttpHeaders.TE.equalsIgnoreCase(headerName)) {
+                validateTe = true;
+                continue;
+            }
+            if (request.getFirstHeader(headerName) != null) {
+                throw new ProtocolException("Header '%s' is illegal for HTTP/2 
messages", headerName);
             }
         }
+
+        if (validateTe) {
+            validateTE(request);
+        }
+    }
+
+    private static void validateTE(final HttpRequest request) throws 
ProtocolException {
+        boolean sawAnyToken = false;
+        for (final Iterator<String> it = MessageSupport.iterateTokens(request, 
HttpHeaders.TE); it.hasNext(); ) {
+            final String token = it.next();
+            sawAnyToken = true;
+            if (!"trailers".equalsIgnoreCase(token)) {
+                throw new ProtocolException(
+                        "Header '%s: %s' is illegal for HTTP/2 messages", 
HttpHeaders.TE, token);
+            }
+        }
+        if (!sawAnyToken && request.getFirstHeader(HttpHeaders.TE) != null) {

Review Comment:
   You need some equivalent of sawAnyToken if you want to reject these cases:
   
   - TE:
   - TE:
   - TE: , , (only separators / whitespace)



-- 
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