Search code examples
javahttp-headersapache-httpclient-4.xspring-oauth2

java.net.SocketException: Connection reset, large HTTP headers


I'm using org.apache.http.impl.client.CloseableHttpClient to send a request. Whenever the size of one of the headers is large (around 103452 bytes), I get a:

java.net.SocketException: Connection reset

The connection is probably not being reset by the server, since other clients from other java apps (probably using a spring OAUTH/REST client) appear to be able to use the service while sending similarly large headers.

Even though the proper fix is to avoid the need to send such a large header in the first place, is there a configuration of org.apache.http.impl.client.CloseableHttpClient that will prevent it from crashing on large headers?

The client is built with:

HttpClientBuilder.create().useSystemProperties().build()

Solution

  • How sure are you the server isn't rejecting the request?

    The HTTP spec doesn't impose a limit, and I don't believe the Apache client imposes one in it's default configuration.

    However, web servers do... See Maximum on http header values? for some details. Note that the limits the web servers impose are for combined size of all headers, not a single header.