windows and http servers on ruby

  • Thread starter Jacek Podkanski
  • Start date
J

Jacek Podkanski

Hi,
I wrote custom webrick servlet which parses *.html files with embedded
ruby code. It works fine on Linux, but on Windows it doesn't work properly
because pictures that are supposed to be on a web page do not show.

What can I do?

#!/usr/bin/ruby
require 'webrick'
include WEBrick

class CustomServlet < HTTPServlet::AbstractServlet
def do_GET(req, resp)
unless defined?(ERB)
@logger.warn "#{self.class}: ERB not defined."
raise HTTPStatus::Forbidden, "ERBHandler cannot work."
end
#puts req.inspect
#puts "++++ #{req.request_uri} +++++++++++++++"
str=req.inspect
path=Dir.pwd+req.path
uri=req.request_uri.to_s
if File.stat(path).directory?
resp.body << "\n<html><head><title>Directory</title></head><body>\n"
resp.body << "<h2>Directory: #{req.path}</h2>"
entries=Dir.entries(path)
resp.body << '<a href="/">Root directory</a>'+"<br>\n"
entries[1..-1].each {|x|
resp.body << '<a href="' << uri
resp.body << '/' if req.path[-1,1] != '/'
resp.body << x << '">'
x='Parent Directory' if x=='..'
resp.body << x << "</a><br>\n"
}
resp.body << "\n</body></html>"
else
#puts 'going to process file '+path
file=File.open(path).read #load normal file
if (path[-5..-1]=='.html' or path[-4..-1]=='.htm')
rhtml=ERB.new(file) #convert served string into code
#rhtml.run #run the code
file=rhtml.result #copy result to another string
resp.body << file
else
resp.body << file
end #if
end #if

end#def
end#class



def start_webrick(config = {})
config.update:)Port => 8080)
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end

start_webrick {|server|
server.mount('/',CustomServlet,"#{Dir.pwd}/proba")
}
 
J

Jacek Podkanski

I don't know if this is your only issue, but there's no "/" (root) on
Windows.
Try a drive letter (e.g. 'c:\').

I also tried that, when i wrote own server based on httpserver class. I
thought it was the issue but it wasn't, all i got was pc speaker
beeping.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top