I've created a simple server Java application using Gradle. As an embedded server , I am using Jetty . I am also using a Gretty plugin as it supports the latest Jetty version.
The project runs just fine . And I have tried to stress test it. As a part of my test I need to check the response time and therefore I am sending "Connection:Close" header via curl.
My response is a long JSON string , and I see only part of it , after which the connection hangs . I would like to know Why is it happening , and how can I work around it.
NOTE :
- When sending
Connection:Keep-aliveheader , everything is fine - When response from the server is not a long string , but smaller . It works just fine (doesn't hang)
- Tried the standard Jetty plugin from gradle , the result was the same.
HOW TO TEST :
- Build and run my project from console
./gradlew appRun - From bash console run
curl -H "Connection:Close" -i "http://localhost:8080/Environment/example" - See the partial response and the connection still alive...
Seems like you are confusing the persistent connection modes between
HTTP/1.0andHTTP/1.1.Either that, or you are using a really old version of
curlthat still defaults toHTTP/1.0.HTTP/1.0has no persistent connections by default, so to use persistent connections we sendConnection: keep-alive.HTTP/1.1uses persistent connections by default, so to disable it we can sendConnection: closeUsing
HTTP/1.0, withConnection: closeis like sending this ...... which produces an invalid header value for
Connectionper theHTTP/1.0specLets use the verbose features of curl to see what's really going on Connection wise...
Example:
HTTP/1.1with normal operation:Notice that it says it kept the connection intact?
Example:
HTTP/1.1with manualConnection: closeoperation:Ah, the HTTP response headers say that the server will close, and curl saw the connection being closed. What we wanted.
Example:
HTTP/1.0with normal operation:See how the HTTP response headers say that the server will close?
Curl also saw the connection being closed.
That's what we expect with normal
HTTP/1.0operation.Example:
HTTP/1.0with persistent connection:Yup, the server indicates that it will use Keep-Alive too (per HTTP/1.0 spec), and curl even concurs and says the connection is left intact.