# Windows and http servers on ruby

**URL:** <https://www.ruby-forum.com/t/windows-and-http-servers-on-ruby/76424>\
**Category:** Ruby\
**Created:** [March 3, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/windows-and-http-servers-on-ruby/76424 "2006-03-03T23:10:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@bigos](https://www.ruby-forum.com/u/bigos)\
**Post date:** [March 3, 2006, 11:10pm UTC](https://www.ruby-forum.com/t/windows-and-http-servers-on-ruby/76424/1 "2006-03-03T23:10:26Z")

</div>

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 \<\< “\nDirectory\n”  
resp.body \<\< “

## Directory: #{req.path}
”  
entries=Dir.entries(path)  
resp.body \<\< ‘Root directory’+"  
\n"  
entries[1…-1].each {|x|  
resp.body \<\< ‘’  
x=‘Parent Directory’ if x==’…’  
resp.body \<\< x \<\< “  
\n”  
}  
resp.body \<\< “\n”  
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")  
}

---

<div class="post-metadata">

**Author:** ![bigos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@bigos](https://www.ruby-forum.com/u/bigos)\
**Post date:** [March 4, 2006, 12:14am UTC](https://www.ruby-forum.com/t/windows-and-http-servers-on-ruby/76424/2 "2006-03-04T00:14:07Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![bigos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f4b2a3/32.png) [@bigos](https://www.ruby-forum.com/u/bigos)\
**Post date:** [March 3, 2006, 11:13pm UTC](https://www.ruby-forum.com/t/windows-and-http-servers-on-ruby/76424/3 "2006-03-03T23:13:28Z")

</div>

Jacek P. wrote:

> 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?

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

Regards,

Dan
