jcabi-http
jcabi-http copied to clipboard
Cancel request
Hi,
would it be possible to cancel a request. My use case is a long polling client that upon shutdown should be able to cancel any currently active request without having to wait for the read timeout.
Regards
Jakob
@yegor256 please, pay attention to this issue
@jakob-o I would recommend to use @Timeable
annotation from jcabi-aspects: http://aspects.jcabi.com/annotation-timeable.html
Hi @yegor256,
if I am not mistaken this is not different (and probably worse) than setting the timeout on the request itself. What I would like to do is to explicitly cancel a running request (e.g. by closing the underlying socket). E.g.
// Thread 1
// Long polling request in a loop
Request request = new JdkRequest("http://www.example.com")
.timeout(1000, 30000): // Long read timeout for long polling request
// Blocks until a response is sent / the read timeout kicks in
request.fetch();
// Thread 2
// System shutdown
// Let's assume this is encapsulated in a shutdown method
request.cancel(); // Closes the socket
Regards
Jakob