ok2c commented on code in PR #620:
URL:
https://github.com/apache/httpcomponents-core/pull/620#discussion_r2813284810
##########
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) {
Review Comment:
@arturobernalg Use `#containsHeader` here. It is a bit nicer.
##########
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:
@arturobernalg This is bad. Why would you want to do a look-up on here,
again? You do you need this line at all? If there has been no
`ProtocolException` no exception at this point, everything is OK.
--
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]