Webrick & HOWTO type docs?

K

Kirk Haines

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
 
K

Kirk Haines

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?


Thanks much,

Kirk Haines
 
M

Michael Neumann

--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

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,

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

--cWoXeonUoKmBZSoM
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="webrick-adaptor.rb"

require 'webrick'
require "socket"
require "iowa/config"

class IOWAServlet < WEBrick::HTTPServlet::AbstractServlet
def service(req, res)
url, = req.request_uri.to_s.split("?")
params = if req.request_method == "GET"
req.query_string || ""
else
req.body
end

url =~ ".*?/iowa/([^/]*)"
socket_name = "#{$tempDir}iowa_#{$1}"
socket = UNIXSocket.new(socket_name)
socket.putc(url.length)
socket.write(url)
socket.putc(params.length)
socket.write(params)
socket.shutdown(1)

body = ""
while (recv = socket.recv(1000)) != "" do
body << recv
end

res['Content-type'] = "text/html"
res.body = body
end
end

if __FILE__ == $0
s = WEBrick::HTTPServer.new(
:port => 2000,
:DocumentRoot => '/home/michael/htdocs',
:Logger => WEBrick::Log::new($stderr, WEBrick::Log::DEBUG)
)

s.mount("/iowa", IOWAServlet)
trap("INT"){ s.shutdown }
s.start
end

--cWoXeonUoKmBZSoM--
 
K

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.

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
 
K

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

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
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top