Sha256: 73108e4d81a216ae188a402a56c184b0480b8d3dd73c69a39fa62ff3eea1cf4d

Contents?: true

Size: 1.4 KB

Versions: 15

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

15 entries across 15 versions & 2 rubygems

Version Path
HeSYINUvSBZfxqA-veewee-0.203.3 lib/veewee/web.rb
HeSYINUvSBZfxqA-veewee-0.203.2 lib/veewee/web.rb
HeSYINUvSBZfxqA-veewee-0.203.1 lib/veewee/web.rb
veewee-0.2.3 lib/veewee/web.rb
veewee-0.2.2 lib/veewee/web.rb
veewee-0.2.1 lib/veewee/web.rb
HeSYINUvSBZfxqA-veewee-0.2.0.2 lib/veewee/web.rb
veewee-0.2.0 lib/veewee/web.rb
veewee-0.1.29 lib/veewee/web.rb
veewee-0.1.28 lib/veewee/web.rb
veewee-0.1.27 lib/veewee/web.rb
veewee-0.1.26 lib/veewee/web.rb
veewee-0.1.25 lib/veewee/web.rb
veewee-0.1.24 lib/veewee/web.rb
veewee-0.1.23 lib/veewee/web.rb