Deepak Kataria
Deepak Kataria

Reputation: 89

How to close jetty Http Connection after the web service method is executed

While configuring embedded jetty server in jetty 9.3.8, I am adding a connection listener to the server connector for keeping track of opening and closing of jetty HttpConnection.

The jetty thread [qtp..........] that is serving current request opens up a HttpConnection. After finishing the current request, how do i inform the jetty to close this HttpConnection. I do see closing of all opened connections in the callback from the listener from different clients after some time of serving the request.

I need to close the connection once i finish with the request, that is when i am done with a particular client.

Upvotes: 1

Views: 2353

Answers (2)

Jason
Jason

Reputation: 2076

Try setting this header in the request: Connection: close

Upvotes: 1

Joakim Erdfelt
Joakim Erdfelt

Reputation: 49462

Closing of the connection is the responsibility of the HTTP spec and protocol.

Note: Be aware that connection close is HTTP version specific, following different semantics for HTTP/1.0 vs HTTP/1.1 vs HTTP/2

In general, the connection open/close handling is negotiated between the HTTP client and the HTTP server, and needs to follow those rules. Having the server arbitrarily close the connection based on some non HTTP spec behavior is ripe for abuse and will cause problems with intermediaries (such as proxies, routers, load balancers, caching servers, etc).

Upvotes: 1

Related Questions