<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
hi all, another request for comments :-)<br>
<br>
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.<br>
<br>
HttpServer basically offers the following ways of processing HTTP
requests:<br>
<br>
* HttpListener() <br>
* HttpModule<br>
* Controllers<br>
<br>
== HttpListener ==<br>
<br>
HttpListener (not the .NET one!) basically works like this:<br>
<blockquote>HttpListener listener;<br>
listener = new HttpListener(IPAddress.Any, 80);<br>
listener.RequestHandler += OnRequest;<br>
listener.Start(5);<br>
</blockquote>
with OnRequest like this:<br>
<blockquote>void OnRequest(HttpClientContext client, HttpRequest
request)<br>
{<br>
    ...<br>
    client.Respond(...);<br>
}<br>
</blockquote>
to support HTTPS, all we need to do is load an X509 certificate and
pass that in to the HttpListener constructor.<br>
<br>
== HttpModule ==<br>
<br>
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.<br>
<br>
== Controller ==<br>
<br>
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"<br>
<blockquote><span
 id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel"><a
 class="moz-txt-link-freetext" href="http://localhost/user/view/1">http://localhost/user/view/1</a>   
  <br>
  <br>
  </span></blockquote>
<span id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel"><small>(example
from
<a class="moz-txt-link-freetext"
 href="http://www.codeplex.com/webserver/Wiki/View.aspx?title=Part%20five%20-%20Using%20controllers&referringTitle=Home">http://www.codeplex.com/webserver/Wiki/View.aspx?title=Part%20five%20-%20Using%20controllers&referringTitle=Home</a>)<br>
<br>
</small></span><span
 id="ctl00_ctl00_Content_TabContentPanel_Content_wikiSourceLabel">would
address the controller module User (or UserController) and invoke the
method View() with the value "1".<br>
<br>
<br>
== Authentication ==<br>
</span><br>
Authentication is via Authentication modules as well as via callbacks
where required (for example for DigestAuthentication the callback
occurs to get the password).<br>
<br>
<br>
== making use of HttpServer ==<br>
<br>
what i'd actually like to implement (either as an HttpModule or as an
HttpListener handler) is an
event--event handler scheme:<br>
<ul>
  <li>incoming HTTP request is pushed as an OSHttpRequest object into
an HTTP request queue.</li>
  <li>each OSHttpRequest encapsulates <br>
  </li>
  <ul>
    <li>the HTTP request header, <br>
    </li>
    <li>an input stream fed by the remote client, <br>
    </li>
    <li>an output stream feeding the remote client</li>
    <li>method to produce OSHttpResponse object (for signaling
redirects, setting status codes, etc)<br>
    </li>
  </ul>
  <li>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)<br>
  </li>
  <li>event handlers return either</li>
  <ul>
    <li>Pass --- didn't act on it<br>
    </li>
    <li>Handled --- acted on it, response return as out parameter<br>
    </li>
    <li>Detach --- acting on it, taking care of it myself, don't do
anything<br>
    </li>
  </ul>
  <li>if no event handler acted on the OSHttpRequest, we return an
error code</li>
  <li>as soon as as we get a Handled or Detached response we stop going
through the handlers</li>
  <li>if we get a Handled we OSHttpResponse.SendHeaders and close the
input and output streams</li>
</ul>
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.<br>
<br>
BaseHttpServer would offer two events to which event handlers could
attach: OnHttpRequest and OnHttpsRequest.<br>
<br>
<br>
what do you think?<br>
<br>
    cheers,<br>
    dr scofield/dirk<br>
<br>
<pre class="moz-signature" cols="80">-- 
dr dirk husemann ---- virtual worlds research ---- ibm zurich research lab
SL: dr scofield ---- <a class="moz-txt-link-abbreviated"
 href="mailto:drscofield@xyzzyxyzzy.net">drscofield@xyzzyxyzzy.net</a> ---- <a
 class="moz-txt-link-freetext" href="http://xyzzyxyzzy.net/">http://xyzzyxyzzy.net/</a>
RL: <a class="moz-txt-link-abbreviated" href="mailto:hud@zurich.ibm.com">hud@zurich.ibm.com</a> - +41 44 724 8573 - <a
 class="moz-txt-link-freetext" href="http://www.zurich.ibm.com/%7Ehud/">http://www.zurich.ibm.com/~hud/</a>
</pre>
</body>
</html>