Webrick & HOWTO type docs?

I think I know the answer to this already, but…

Are there any not-so-easy-to-find documents anywhere on using Webrick? API
docs or howto docs or anything like that?

I’m going to make Iowa capable of using webrick so that an Iowa application
can be a completely standalone application server. From what I can tell,
this graft looks like it should be an extremely simple one, but I haven’t
been able to find a lot of documentation so I’m mostly going to be working
from looking at the webrick code and at other pieces of software that use
it, unless someone can point me to something that I have missed.

If there is nothing, then I will try to document what I learn while I go
about this project as a way to start making some practical HOWTO type
documentation available for webrick.

Thanks,

Kirk Haines

I haven’t found any, but the Servlets provided with WEBrick are a good
start. Here’s a template:

class MyServlet < WEBrick::HTTPServlet::AbstractServlet

···

Kirk Haines (khaines@enigo.com) wrote:

I think I know the answer to this already, but…

Are there any not-so-easy-to-find documents anywhere on using Webrick? API
docs or howto docs or anything like that?

I’m going to make Iowa capable of using webrick so that an Iowa application
can be a completely standalone application server. From what I can tell,
this graft looks like it should be an extremely simple one, but I haven’t
been able to find a lot of documentation so I’m mostly going to be working
from looking at the webrick code and at other pieces of software that use
it, unless someone can point me to something that I have missed.

If there is nothing, then I will try to document what I learn while I go
about this project as a way to start making some practical HOWTO type
documentation available for webrick.

your_arguments stands in for any extra arguments

Of course, you may omit #initialize if you don’t use extra args

def initialize(server, your_arguments)
super

# setup from your_arguments

end

HTTP method handlers are prefixed with do_

def do_GET(request, response)
status, headers, body = do_stuff_with(request)
response.status = status
response.headers = headers
response.body = body
end

alias do_POST do_GET

end

To mount the servlet:

server = WEBrick::HTTPServer.new
server.mount “/some/path”, MyServlet, any_extra_args

Any arguments after the servlet class get passed to the servlet’s #new
method.

Here’s the one I use for Borges:

http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/borges/lib/Borges/WEBrick.rb?rev=1.13&cvsroot=borges&content-type=text/vnd.viewcvs-markup

Thanks,

Kirk Haines


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

I wrote such a thing for Iowa 0.14a (it's appended). Don't know if it still works with
the current Iowa release.

Regards,

  Michael

webrick-adaptor.rb (967 Bytes)

···

On Tue, May 25, 2004 at 05:12:24AM +0900, Kirk Haines wrote:

I think I know the answer to this already, but....

Are there any not-so-easy-to-find documents anywhere on using Webrick? API
docs or howto docs or anything like that?

I'm going to make Iowa capable of using webrick so that an Iowa application
can be a completely standalone application server. From what I can tell,

Thanks, Eric. I have two questions about the servlet architecture:

  1. Can the code that executes the server.mount() dynamically alter the mount
    points? i.e. when a configuration file changes either add to or remove
    mount points?

  2. What if a person has a list of a couple hundred URLs that they want
    mounted to the servlet? Will that be ugly with Webrick, or no problem?

Thanks much,

Kirk Haines

···

On Mon, 24 May 2004 13:34:01 -0700, Eric Hodel wrote

To mount the servlet:

server = WEBrick::HTTPServer.new
server.mount “/some/path”, MyServlet, any_extra_args

Cool. It won’t work with the current release, but it should help give me a
push in the right direction. Thank you very much.

Kirk Haines

···

On Tue, 25 May 2004 05:48:09 +0900, Michael Neumann wrote

I wrote such a thing for Iowa 0.14a (it’s appended). Don’t know if
it still works with the current Iowa release.

These two questions tell me you have one instance that handles many
URLs. Instead of handling this in WEBrick, create a servlet that
handles one level up, and add a dispatcher to it (or inside IOWA, if you
already have one written).

(Instead of mounting /foo/bar and /foo/baz, mount a servlet at /foo.)

···

Kirk Haines (khaines@enigo.com) wrote:

On Mon, 24 May 2004 13:34:01 -0700, Eric Hodel wrote

To mount the servlet:

server = WEBrick::HTTPServer.new
server.mount “/some/path”, MyServlet, any_extra_args

Thanks, Eric. I have two questions about the servlet architecture:

  1. Can the code that executes the server.mount() dynamically alter the
    mount points? i.e. when a configuration file changes either add to or
    remove mount points?

  2. What if a person has a list of a couple hundred URLs that they want
    mounted to the servlet? Will that be ugly with Webrick, or no
    problem?


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

What I would like to replicate is basically how I have it working with my
mod_ruby handler under Apache.

Basically, I have a list of paths. IF a request matches one of the paths in
the list, the request goes to Iowa for handling. If not, then it gets
handled by the web server. So, really, I want to mount /, but then
selectively fall through to let something other than the servlet handle the
request.

If I can do this, then with the ability of Webrick to serve regular content,
an entire application can be handled, along with graphics or static files,
from Webrick. It will make it extremely easy to bring an Iowa application
up.

Thanks,

Kirk Haines

···

On Mon, 24 May 2004 14:24:50 -0700, Eric Hodel wrote

These two questions tell me you have one instance that handles many
URLs. Instead of handling this in WEBrick, create a servlet that
handles one level up, and add a dispatcher to it (or inside IOWA, if
you already have one written).

(Instead of mounting /foo/bar and /foo/baz, mount a servlet at /foo.)

It sounds like a subclass of FileServlet would fit perfectly. If its
not in the list of paths, super knows what to do.

···

Kirk Haines (khaines@enigo.com) wrote:

On Mon, 24 May 2004 14:24:50 -0700, Eric Hodel wrote

These two questions tell me you have one instance that handles many
URLs. Instead of handling this in WEBrick, create a servlet that
handles one level up, and add a dispatcher to it (or inside IOWA, if
you already have one written).

(Instead of mounting /foo/bar and /foo/baz, mount a servlet at /foo.)

What I would like to replicate is basically how I have it working with
my mod_ruby handler under Apache.

Basically, I have a list of paths. IF a request matches one of the
paths in the list, the request goes to Iowa for handling. If not,
then it gets handled by the web server. So, really, I want to mount
/, but then selectively fall through to let something other than the
servlet handle the request.

If I can do this, then with the ability of Webrick to serve regular
content, an entire application can be handled, along with graphics or
static files, from Webrick. It will make it extremely easy to bring
an Iowa application up.


Eric Hodel - drbrain@segment7.net - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04