Module: Veewee::Provider::Core::Helper::Web

Included in:
Box
Defined in:
lib/veewee/provider/core/helper/web.rb

Instance Method Summary collapse

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, options) # start in new thread
  server_for_http_request(filename, urlname, options.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, 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
  Timeout.timeout(timeout) do
    server =
    ::WEBrick::HTTPServer.new(
      :Port => options[:port],
      :Logger => webrick_logger,
      :AccessLog => webrick_logger
    )
    env.logger.debug("mounting file #{urlname}")
    server.mount("#{urlname}", Veewee::Provider::Core::Helper::Servlet::FileServlet, filename, ui, options[: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: #{options[: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, options) # original blocking
  server_for_http_request(filename, urlname, options) do |server|
    server.start
  end
end