[Opensim-dev] HttpServer overview & RFC

Sean Dague sean at dague.net
Wed May 28 18:47:41 UTC 2008


On Wed, May 28, 2008 at 08:07:23AM +0200, Dr Scofield wrote:
>    hi all, another request for comments :-)

First, +1 on the approach here.  A couple of questions / comments in
line just to educate myself.

>    i've been chewing on HttpServer and how to use it instead of the .NET
>    HttpListener stuff. here's first a short overview of HttpServer and
>    what it offers (keyword is "short", for more details have a look at
>    opensim-libs/HttpServer), then some thoughts on how we could make use
>    of it.
>    HttpServer basically offers the following ways of processing HTTP
>    requests:
>    * HttpListener()
>    * HttpModule
>    * Controllers
>    == HttpListener ==
>    HttpListener (not the .NET one!) basically works like this:
> 
>      HttpListener listener;
>      listener = new HttpListener(IPAddress.Any, 80);
>      listener.RequestHandler += OnRequest;
>      listener.Start(5);
> 
>    with OnRequest like this:
> 
>      void OnRequest(HttpClientContext client, HttpRequest request)
>      {
>          ...
>          client.Respond(...);
>      }
> 
>    to support HTTPS, all we need to do is load an X509 certificate and
>    pass that in to the HttpListener constructor.

Sounds very promissing.

>    == HttpModule ==
>    HttpModule basically allows us to register an HttpModule derived object
>    with an HttpServer object (which internally uses HttpListener). Each
>    registered module gets invoked to handle an incoming request (similar
>    to the handler idea alan webb brainstormed about a couple of days ago)
>    and can signal back whether it has handled the request.
>
>    == Controller ==
>    Controller finally is kind of a pre-canned REST handler making use of
>    the first three parts of an URL (slash is separator) as "addressing"
> 
>      [1]http://localhost/user/view/1
> 
>    (example from
>    [2]http://www.codeplex.com/webserver/Wiki/View.aspx?title=Part%20five%2
>    0-%20Using%20controllers&referringTitle=Home)
>    would address the controller module User (or UserController) and invoke
>    the method View() with the value "1".

Nice, you built .net on rails routing. :)

>    == Authentication ==
>    Authentication is via Authentication modules as well as via callbacks
>    where required (for example for DigestAuthentication the callback
>    occurs to get the password).
>    == making use of HttpServer ==
>    what i'd actually like to implement (either as an HttpModule or as an
>    HttpListener handler) is an event--event handler scheme:
>      * incoming HTTP request is pushed as an OSHttpRequest object into an
>        HTTP request queue.
>      * each OSHttpRequest encapsulates
> 
>      * the HTTP request header,
>      * an input stream fed by the remote client,
>      * an output stream feeding the remote client
>      * method to produce OSHttpResponse object (for signaling redirects,
>        setting status codes, etc)
> 
>      we have a pool of OSHttpRequest pumps that take OSHttpRequest objects
>    and pump them via the registered event handlers to whoever registered
>    an interest (via multicast mechanism that stefan already explained a
>    couple of days ago as well)
> 
>      event handlers return either
>      * Pass --- didn't act on it
>      * Handled --- acted on it, response return as out parameter
>      * Detach --- acting on it, taking care of it myself, don't do
>        anything

Can you give an example of Handled vs. Detach usage?

>      if no event handler acted on the OSHttpRequest, we return an error
>    code
>
>      as soon as as we get a Handled or Detached response we stop going
>    through the handlers
> 
>      if we get a Handled we OSHttpResponse.SendHeaders and close the input
>    and output streams any event handler that returns Detached is
>    responsible for sending response header and for dealing with the input
>    and output stream itself --- and could, for example, keep an HTTP
>    connection open, implementing a long poll scheme, for example.
>    BaseHttpServer would offer two events to which event handlers could
>    attach: OnHttpRequest and OnHttpsRequest.
>    what do you think?
>        cheers,
>        dr scofield/dirk

	 -Sean

-- 
__________________________________________________________________

Sean Dague                                       Mid-Hudson Valley
sean at dague dot net                            Linux Users Group
http://dague.net                                 http://mhvlug.org

There is no silver bullet.  Plus, werewolves make better neighbors
than zombies, and they tend to keep the vampire population down.
__________________________________________________________________
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080528/d409cc90/attachment-0001.pgp>


More information about the Opensim-dev mailing list