[Opensim-dev] HttpServer overview & RFC

Frisby, Adam adam at deepthink.com.au
Wed May 28 16:28:56 UTC 2008


Looks good!

 

+1

 

Adam

 

From: opensim-dev-bounces at lists.berlios.de
[mailto:opensim-dev-bounces at lists.berlios.de] On Behalf Of Dr Scofield
Sent: Wednesday, 28 May 2008 2:07 AM
To: opensim-dev at lists.berlios.de
Subject: [Opensim-dev] HttpServer overview & RFC

 

hi all, another request for comments :-)

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.

== 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"

http://localhost/user/view/1    




(example from
http://www.codeplex.com/webserver/Wiki/View.aspx?title=Part%20five%20-%2
0Using%20controllers&referringTitle=Home)

would address the controller module User (or UserController) and invoke
the method View() with the value "1".


== 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

*	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




-- 
dr dirk husemann ---- virtual worlds research ---- ibm zurich research
lab
SL: dr scofield ---- drscofield at xyzzyxyzzy.net ----
http://xyzzyxyzzy.net/
RL: hud at zurich.ibm.com - +41 44 724 8573 -
http://www.zurich.ibm.com/~hud/ <http://www.zurich.ibm.com/%7Ehud/> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://opensimulator.org/pipermail/opensim-dev/attachments/20080528/778f82a9/attachment-0001.html>


More information about the Opensim-dev mailing list