Sha256: 7fe6059ba4c1b32ba036d2d2a63dfbdc3ba240f9c83438b9a6b21e37da3e9596

Contents?: true

Size: 1.4 KB

Versions: 22

Compression:

Stored size: 1.4 KB

Contents

module Veewee
  class Web

    require 'webrick'
    include WEBrick

    class FileServlet < WEBrick::HTTPServlet::AbstractServlet
             
              def initialize(server,localfile)
                super(server)
                @server=server
                @localfile=localfile
              end
             def do_GET(request,response)
                     response['Content-Type']='text/plain'
                     response.status = 200
                     puts "Serving file #{@localfile}"                     
                     displayfile=File.open(@localfile,'r')
                     content=displayfile.read()
                     response.body=content
                     #If we shut too fast it might not get the complete file
                     sleep 2
                     @server.shutdown
             end
     end 

    def self.wait_for_request(filename,options={:timeout => 10, :web_dir => "", :port => 7125})  
      
      webrick_logger=WEBrick::Log.new("/dev/null", WEBrick::Log::INFO)
      
      web_dir=options[:web_dir]
      filename=filename
      s= HTTPServer.new(
        :Port => options[:port],
        :Logger => webrick_logger,
        :AccessLog => webrick_logger
      )
      s.mount("/#{filename}", FileServlet,File.join(web_dir,filename))
      trap("INT"){
          s.shutdown
          puts "Stopping webserver"
          exit
        }
      s.start
    end
    
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
veewee-0.1.22 lib/veewee/web.rb
veewee-0.1.21 lib/veewee/web.rb
veewee-0.1.20 lib/veewee/web.rb
veewee-0.1.19 lib/veewee/web.rb
veewee-0.1.18 lib/veewee/web.rb
veewee-0.1.17 lib/veewee/web.rb
veewee-0.1.16 lib/veewee/web.rb
veewee-0.1.15 lib/veewee/web.rb
veewee-0.1.14 lib/veewee/web.rb
veewee-0.1.13 lib/veewee/web.rb
veewee-0.1.12 lib/veewee/web.rb
veewee-0.1.11 lib/veewee/web.rb
veewee-0.1.10 lib/veewee/web.rb
veewee-0.1.9 lib/veewee/web.rb
veewee-0.1.8 lib/veewee/web.rb
veewee-0.1.7 lib/veewee/web.rb
veewee-0.1.6 lib/veewee/web.rb
veewee-0.1.5 lib/veewee/web.rb
veewee-0.1.4 lib/veewee/web.rb
veewee-0.1.3 lib/veewee/web.rb