lib/veewee/provider/core/helper/web.rb in veewee-0.3.12 vs lib/veewee/provider/core/helper/web.rb in veewee-0.4.0
- old
+ new
@@ -1,16 +1,16 @@
module Veewee
module Provider
module Core
module Helper
require 'webrick'
+
include WEBrick
+
module Servlet
-
class FileServlet < WEBrick::HTTPServlet::AbstractServlet
-
attr_reader :ui, :threaded
def initialize(server,localfile,ui,threaded)
super(server)
@server=server
@@ -35,48 +35,47 @@
ui.info "Shutting down for #{@localfile}"
@server.shutdown
end
end
end
-
end
- module Web
- def wait_for_http_request(filename,options) # original blocking
- s = server_for_http_request(filename,options)
+ module Web
+ def wait_for_http_request(filename, urlname, options) # original blocking
+ s = server_for_http_request(filename, urlname, options)
s.start
end
- def allow_for_http_request(filename,options) # start in new thread
- s = server_for_http_request(filename,options.merge({:threaded => false}))
+ def allow_for_http_request(filename, urlname, options) # start in new thread
+ s = server_for_http_request(filename, urlname, options.merge({:threaded => false}))
Thread.new { s.start }
end
- def server_for_http_request(filename,options={:timeout => 10, :web_dir => "", :port => 7125, :threaded => false})
+ def server_for_http_request(filename, urlname, options={:timeout => 10, :port => 7125, :threaded => false})
# 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)
- web_dir=options[:web_dir]
- filename=filename
s= ::WEBrick::HTTPServer.new(
:Port => options[:port],
:Logger => webrick_logger,
:AccessLog => webrick_logger
)
- mount_filename = filename.start_with?('/') ? filename : "/#{filename}"
- env.logger.debug("mounting file #{mount_filename}")
- s.mount("#{mount_filename}", Veewee::Provider::Core::Helper::Servlet::FileServlet,File.join(web_dir,filename),ui,options[:threaded])
+
+ env.logger.debug("mounting file #{urlname}")
+
+ s.mount("#{urlname}", Veewee::Provider::Core::Helper::Servlet::FileServlet, filename, ui, options[:threaded])
+
trap("INT"){
s.shutdown
ui.info "Stopping webserver"
exit
}
+
s
end
-
end #Class
end #Module
end #Module
end #Module
end #Module