Skip to content

Commit

Permalink
Validate multiple TE header
Browse files Browse the repository at this point in the history
  • Loading branch information
arturobernalg committed Oct 19, 2024
1 parent 925c1f6 commit 6354916
Showing 1 changed file with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.EntityDetails;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HeaderElements;
import org.apache.hc.core5.http.HttpException;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpRequest;
Expand All @@ -44,6 +43,7 @@
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.Tokenizer;


/**
* HTTP protocol interceptor responsible for validating and processing the {@link HttpHeaders#TE} header field in HTTP/1.1 requests.
* <p>
Expand Down Expand Up @@ -98,16 +98,14 @@ public void process(final HttpRequest request, final EntityDetails entity, final
throws HttpException, IOException {
Args.notNull(request, "HTTP request");

// Fetch the TE header
final Header teHeader = request.getFirstHeader(HttpHeaders.TE);

if (teHeader == null) {
return; // No further validation needed
// Fetch all TE headers
final Header[] teHeaders = request.getHeaders(HttpHeaders.TE);
if (teHeaders != null && teHeaders.length > 0) {
for (final Header teHeader : teHeaders) {
validateTEField(teHeader.getValue());
}
validateConnectionHeaders(request);
}

final String teValue = teHeader.getValue();
validateTEField(teValue);
validateConnectionHeaders(request);
}

/**
Expand Down Expand Up @@ -142,7 +140,7 @@ private void validateTEField(final String teValue) throws HttpException {
continue;
}

if (HeaderElements.CHUNKED_ENCODING.equalsIgnoreCase(member)) {
if ("chunked".equalsIgnoreCase(member)) {
throw new ProtocolException("'chunked' transfer coding must not be listed in the TE header for HTTP/1.1.");
}

Expand Down

0 comments on commit 6354916

Please sign in to comment.