Class: Veewee::Web::FileServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/veewee/web.rb

Instance Method Summary collapse

Constructor Details

#initialize(server, localfile) ⇒ FileServlet

Returns a new instance of FileServlet.



9
10
11
12
13
# File 'lib/veewee/web.rb', line 9

def initialize(server,localfile)
  super(server)
  @server=server
  @localfile=localfile
end

Instance Method Details

#do_GET(request, response) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/veewee/web.rb', line 14

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