jcabi-http icon indicating copy to clipboard operation
jcabi-http copied to clipboard

Cancel request

Open jakob-o opened this issue 7 years ago • 3 comments

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

jakob-o avatar Jun 01 '17 15:06 jakob-o

@yegor256 please, pay attention to this issue

0crat avatar Jun 01 '17 15:06 0crat

@jakob-o I would recommend to use @Timeable annotation from jcabi-aspects: http://aspects.jcabi.com/annotation-timeable.html

yegor256 avatar Jun 02 '17 07:06 yegor256

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

jakob-o avatar Jun 02 '17 08:06 jakob-o