Another announcement of Mongrel – the fastest little web server
library for Ruby yet. This release is nice in that it should build
on win32 better and it now sports a small DirHandler that can serve
directories and files. This means Mongrel is closer to replacing
WEBrick as a Rails debug runner.
And they’ll get the new gear. You can go back to the project page
and download the source .tgz if you installed using that.
== Changes
Fixed a header so that win32 folks can build it.
Added all CGI parameters that didn’t cause security or performance
problems.
Forced the sockets to not do reverse name lookup (huge performance
hit for little benefit).
Created a REQUEST_URI parameter that has the original untouched URI
used in the request. This is the string used to lookup the handlers
and create the SCRIPT_NAME and PATH_INFO parameters.
Implemented a basic directory serving handler called DirHandler.
It will serve files in a directory, print a simple directory listing,
and tries to protect against malicious path requests.
Some minor code clean-ups and additional documentation regarding
constants used.
== The DirHandler
The really simple DirHandler is used like this (from the examples/
simpletest.rb file):
h = Mongrel::HttpServer.new(“0.0.0.0”, “3000”)
h.register(“/files”, Mongrel::DirHandler.new(“.”))
h.run.join
This simply sets things up so that when people go to /files, they get
the contents of the current directory. The DirHandler expands the
path you give it so that when requests come in, it can expand them
too and make sure that both paths have the same prefix. If not it
will reject them. There is also an option to turn off the directory
listings using the second parameter to DirHandler.new().
This initial file serving is very simplistic since it doesn’t map
extensions to mime types yet. It should be a good start for some
people though.
== Feedback
Thanks for all the feedback and bug reports so far. With directory
serving and complete CGI parameters out of the way I’m going to start
working on a Rails runner using Mongrel next, and possibly a caching
system. Goal for the weekend will be to get a Rails application
running in Mongrel standalone.
Forced the sockets to not do reverse name lookup (huge performance
== The DirHandler
path you give it so that when requests come in, it can expand them
Like Daniel S. in the previous version I’m getting errors when
attempting the following on windows:
irb(main):001:0> require_gem ‘mongrel’
=> true
irb(main):002:0> p Mongrel
NameError: uninitialized constant Mongrel
from (irb):2
irb(main):003:0>
Looking at the gem install itself, everything seems to have been created
correctly. I have a mongrel.rb in mongrel’s lib dir, just can’t seem to
get
it to actually LOAD correctly. Any help would be great.
directories and files. This means Mongrel is closer to replacing
and tries to protect against malicious path requests.
h.run.join
people though.
Enjoy!
irb(main):001:0> require_gem ‘mongrel’
Sorry for the double post, but as it turns out I get an Identical error
on
my Debian box as well, so something in the install seems to be a bit
fubar’d.
Did you make sure to require rubygems first? Here’s my install:
`require’
from (irb):2
irb(main):003:0>
Are you sure that you don’t have any previous versions of Mongrel
installed via source? Or is ./mongrel.rb a file you’re working on
that’s
getting loaded when you do require? The reason I ask is “from
./mongrel.rb:4” means that you’re trying to use Mongrel modules at line
4.
When I look at line 4 of the mongrel.rb library it’s a “require
‘stringio’” line. So, that error has to be coming from somewhere else.
Make sure you can identify all the “mongrel.rb” files on your system and
that you’re not loading the wrong one on accident.
=> true
installed via source? Or is ./mongrel.rb a file you’re working on that’s
getting loaded when you do require? The reason I ask is “from
./mongrel.rb:4” means that you’re trying to use Mongrel modules at line 4.
When I look at line 4 of the mongrel.rb library it’s a “require
‘stringio’” line. So, that error has to be coming from somewhere else.
Make sure you can identify all the “mongrel.rb” files on your system and
that you’re not loading the wrong one on accident.
Hah, interesting side note. Don’t name the test file mongrel.rb when
attempting to test a file with a library named mongrel.rb. Well that
was an
interesting bug to track down. Thanks
Zed A. Shaw
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.