Module: Veewee::Provider::Core::Helper::Web
- Included in:
- Box
- Defined in:
- lib/veewee/provider/core/helper/web.rb
Instance Method Summary collapse
-
#allow_for_http_request(filename, urlname, options) ⇒ Object
start in new thread.
- #server_for_http_request(filename, urlname, options, &block) ⇒ Object
-
#wait_for_http_request(filename, urlname, options) ⇒ Object
original blocking.
Instance Method Details
#allow_for_http_request(filename, urlname, options) ⇒ Object
start in new thread
50 51 52 53 54 55 |
# File 'lib/veewee/provider/core/helper/web.rb', line 50 def allow_for_http_request(filename, urlname, ) # start in new thread server_for_http_request(filename, urlname, .merge({:threaded => false})) do |server| t = Thread.new { server.start } t.abort_on_exception = true end end |
#server_for_http_request(filename, urlname, options, &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/veewee/provider/core/helper/web.rb', line 57 def server_for_http_request(filename, urlname, , &block) # Calculate the OS equivalent of /dev/null , on windows this is NUL: # http://www.ruby-forum.com/topic/115472 fn = test(?e, '/dev/null') ? '/dev/null' : 'NUL:' webrick_logger = WEBrick::Log.new(fn, WEBrick::Log::INFO) timeout = [:timeout] || 60 Timeout.timeout(timeout) do server = ::WEBrick::HTTPServer.new( :Port => [:port], :Logger => webrick_logger, :AccessLog => webrick_logger ) env.logger.debug("mounting file #{urlname}") server.mount("#{urlname}", Veewee::Provider::Core::Helper::Servlet::FileServlet, filename, ui, [:threaded]) trap("INT"){ server.shutdown ui.info "Stopping webserver" exit } yield server end rescue Timeout::Error server.shutdown unless server.nil? raise "File #{filename.inspect} was not requested in #{timeout}seconds, are you using firewall blocking connections to port: #{[:port]}?" end |
#wait_for_http_request(filename, urlname, options) ⇒ Object
original blocking
44 45 46 47 48 |
# File 'lib/veewee/provider/core/helper/web.rb', line 44 def wait_for_http_request(filename, urlname, ) # original blocking server_for_http_request(filename, urlname, ) do |server| server.start end end |