Http request inside controller?

hi all,
i got problem with net/http inside controller. I need to respond to
action using some remote (not REST compatible) http server (actually
returning pdf file) so inside action i use:

  response = Net::HTTP.new('1.2.3.4').request_get('/url')
  send_data http_response.body, :filename => "test.pdf", :type =>

“application/pdf”

…with no luck :frowning: I got:

Timeout::Error in InvoicesController#pdf

execution expired

RAILS_ROOT: C:/work/z
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/1.8/timeout.rb:54:in rbuf_fill' c:/ruby/lib/ruby/1.8/timeout.rb:56:intimeout’
c:/ruby/lib/ruby/1.8/timeout.rb:76:in timeout' c:/ruby/lib/ruby/1.8/net/protocol.rb:132:inrbuf_fill’
c:/ruby/lib/ruby/1.8/net/protocol.rb:116:in readuntil' c:/ruby/lib/ruby/1.8/net/protocol.rb:126:inreadline’
c:/ruby/lib/ruby/1.8/net/http.rb:2029:in read_status_line' c:/ruby/lib/ruby/1.8/net/http.rb:2018:inread_new’
c:/ruby/lib/ruby/1.8/net/http.rb:1059:in request' c:/ruby/lib/ruby/1.8/net/http.rb:1046:inrequest’
c:/ruby/lib/ruby/1.8/net/http.rb:547:in start' c:/ruby/lib/ruby/1.8/net/http.rb:1044:inrequest’
c:/ruby/lib/ruby/1.8/net/http.rb:957:in request_get' app/controllers/invoices_controller.rb:48:inpdf’

on ethereal i trully see that there is no response to GET but what is
interesting the same net/http code inside rake task is successfuly
downloading and saving the file locally.

What could be the problem with net/http requests inside controllers? i
may only guess that in may not be thread safe or what as controllers
use net/http mechanism for own pursposes. how to solve this issue -
any ideas?

big thanks in advance

br

K

Hi,

Can you access any other sites using http from within your
controllers?
I see you are using Windows - does firewall allow your mongrels/
webrick to access Internet?

If it’s timeout issue, you can easily increase timeout with net/http
library like:

Net::HTTP.start(‘www.whatever.org.uk’) { |http|
http.open_timeout = http.read_timeout = 60 # You increase
timeout for connections
req = Net::HTTP::Get.new(“/index.html”)
resp = http.request(req)
}

page_content = resp.body

Best,
H.

On 26 Wrz, 01:00, Hubert £êpicki [email protected] wrote:

Hi,

Can you access any other sites using http from within your
controllers?

yes, I can so it is not rails problem, thank you - i will examine
remote server why it is not responding to every request