lib/veewee/provider/core/helper/web.rb in veewee-0.4.4 vs lib/veewee/provider/core/helper/web.rb in veewee-0.4.5.pre1

- old
+ new

@@ -40,28 +40,29 @@ end end module Web def wait_for_http_request(filename, urlname, options) # original blocking - s = server_for_http_request(filename, urlname, options) - s.start + server_for_http_request(filename, urlname, options) do |server| + server.start + end end def allow_for_http_request(filename, urlname, options) # start in new thread - s = server_for_http_request(filename, urlname, options.merge({:threaded => false})) - t = Thread.new { s.start } - t.abort_on_exception = true + server_for_http_request(filename, urlname, options.merge({:threaded => false})) do |server| + t = Thread.new { server.start } + t.abort_on_exception = true + end end - def server_for_http_request(filename, urlname, options) + def server_for_http_request(filename, urlname, options, &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 = options[:timeout] || 60 - server = nil Timeout.timeout(timeout) do server = ::WEBrick::HTTPServer.new( :Port => options[:port], :Logger => webrick_logger, @@ -72,9 +73,10 @@ 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: #{options[:port]}?" end