Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any feature in JEE8 for cancelling HTTP 2 request processing

HTTP 1.1 doesn't have any mechanism to ask the server to cancel a request. It is possible to get the input/output/error stream from HttpURLConnection and close them. That would throw IOException on the client side allowing the client to clean up after cancel. The "persistent" or "keepAlive" TCP connection of HTTP 1.1 will continue to exist for future requests. Therefore, the server doesn't get to know about these events on the client side until it tries to write and fails.

HTTP 2 provides a separate frame called RST_STREAM to close a stream or cancel a fired request. Since the Java 9 HttpClient allows us to make asynchronous HTTP request returning a CompletableFuture, there is now a more elegant way to cancel an ongoing request using the cancel() method of CompletableFuture.

My questions:

  1. Does Java 9+ releases actually send the RST_STREAM to the server when cancel() is invoked?
  2. Does JEE8 provide any mechanishm to interrupt the business logic executing against the HTTP request on receipt of the RST_STREAM? Or any plan for future releases?
like image 981
Saptarshi Basu Avatar asked Oct 14 '25 13:10

Saptarshi Basu


1 Answers

In Java 11 to cancel an HTTP/2 request with the java.net.HttpClient you would have to provide your own BodySubscriber (or wrap one of the provided built-in) and cancel the Flow.Subscription. This should reset the HTTP/2 stream.

like image 120
daniel Avatar answered Oct 17 '25 04:10

daniel