Skip to content

Commit

Permalink
[java] Ignoring additional headers in the JDK 11 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Oct 13, 2022
1 parent bc438d4 commit 57db565
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
import org.openqa.selenium.remote.http.HttpResponse;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand All @@ -37,6 +37,8 @@
class JdkHttpMessages {

private final ClientConfig config;
private static final List<String> IGNORE_HEADERS =
List.of("content-length", "connection", "host");

public JdkHttpMessages(ClientConfig config) {
this.config = Objects.requireNonNull(config, "Client config");
Expand Down Expand Up @@ -83,9 +85,8 @@ public java.net.http.HttpRequest createRequest(HttpRequest req) {
}

for (String name : req.getHeaderNames()) {
// Avoid explicitly setting content-length
// This prevents the IllegalArgumentException that states 'restricted header name: "Content-Length"'
if (name.equalsIgnoreCase("content-length")) {
// This prevents the IllegalArgumentException that states 'restricted header name: ...'
if (IGNORE_HEADERS.contains(name.toLowerCase())) {
continue;
}
for (String value : req.getHeaders(name)) {
Expand Down

0 comments on commit 57db565

Please sign in to comment.