Webrick & HOWTO type docs?

Discussion in 'Ruby' started by Kirk Haines, May 24, 2004.

  1. Kirk Haines

    Kirk Haines Guest

    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
     
    Kirk Haines, May 24, 2004
    #1
    1. Advertising

  2. Kirk Haines

    Kirk Haines Guest

    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?


    Thanks much,

    Kirk Haines
     
    Kirk Haines, May 24, 2004
    #2
    1. Advertising

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

    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,


    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--
     
    Michael Neumann, May 24, 2004
    #3
  4. Kirk Haines

    Kirk Haines Guest

    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
     
    Kirk Haines, May 24, 2004
    #4
  5. Kirk Haines

    Kirk Haines Guest

    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
     
    Kirk Haines, May 24, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KYG
    Replies:
    2
    Views:
    971
    Ian Collins
    Aug 18, 2008
  2. Lloyd Zusman
    Replies:
    2
    Views:
    432
  3. Aaron Smith

    WEBrick::Daemon and WEBrick

    Aaron Smith, Mar 9, 2007, in forum: Ruby
    Replies:
    2
    Views:
    340
    Aaron Smith
    Mar 18, 2007
  4. Stéphane Wirtel
    Replies:
    0
    Views:
    214
    Stéphane Wirtel
    Apr 19, 2007
  5. Al
    Replies:
    1
    Views:
    171
    Henry Law
    Oct 16, 2005
Loading...

Share This Page