How to cancel Ruby Net::HTTP request? -


How do I get Ruby's Net :: HTTP Module to cancel a request?

http.finish raises an error below I get the impression that the feedback object does not know that the connection was closed and still more data is expected.

I want to avoid making a head request, therefore, request a GET, as long as the content-type is not HTML, cancel the request.

  net :: HTTP.start (uri.host, uri.port) do. Http | Http.request_get (uri.path) does. Feedback | As long as the feedback ['content type'] = ~ / html / i http.finish end-end end /usr/lib/ruby/1.8/net/http.rb28241: 'stream_check': attempt to read the body outside the block (IoROR ) /usr/lib/ruby/1.8/net/http.rb2171:IN/usr/lib/ruby/1.8/net/http.rbaxy198: In 'read_body' / usr 'body' / usr / lib / ruby ​​/ From `1.8 to` request '/usr/lib/ruby/1.8/net/http.rb:1052: to' reading_body '/lib/ruby/1.8/net/http.rb:3737/nnet/http.rb: 948: `Request_get 'from net.rb: 9 / usr / lib / ruby ​​/ 1.8 / net / http.rbitter43: from / usr / lib / ruby ​​/ 1.8 to' start '/ net / http.rb: 440: from INNET.rb 'Start': 7  

Re-edited, the original answer is below < / Strong>

not me It seems that you are lethargic in the code snippet before your pastie. Try the following to see what I mean:

  h = net :: http.new uri.host, uri.port h.set_debug_output $ stderr h.start do | Http | Http.request_get (uri.path) does. Feedback | End of End  

It is happening that by issuing GET , your client is obliged to read the entire document from the socket, even if you really do not Do it or not. This is just part of the HTTP Tricks.

If you do not react, you prevent your code from reading the response in memory , but the block will not return until all the data is being read. Your block with the socket break calls is breaking before the final read which means that even if you maintain your code, you will not be able to read the answer in the memory. To know what happens to the final reading.

You just have to read an ISO file which is massive, so it seems that you are lethargic.

Answer briefly is that you should issue a HEAD request if you do not intend to read the entire document, such as HTTP Tip Is specified in

The complex answer is that you issue a byte range as specified, but I'm not sure that the Ruby is partial GET The Http Client Library can support this mode of operation. By calling http.finish you are quickly shutting down the TCP socket, which works to break out of the code block, but raises the exception in calling the code because you do this "Expecting" are welcome to call Full If you want to catch exceptions, but you are not playing well with HTTP

Exception is being removed from

If you really want to close the socket quickly, then just grab the IOError.

I just saw you are starting feedback for the result of calling head , but then you can again call it a block parameter Form

only before you are subject to request_get , content_type content type Check it out.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -