Fix due to the modified HttpServer.cs

This commit is contained in:
sta 2012-09-11 13:21:47 +09:00
parent d0e5ae3979
commit 8e2a1ee1b3
62 changed files with 92 additions and 30 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -16,9 +16,9 @@ namespace Example3
{
_httpsv = new HttpServer<Echo>(4649);
_httpsv.OnResponse += (sender, e) =>
_httpsv.OnGet += (sender, e) =>
{
onResponse(e.Context);
onGet(e.Request, e.Response);
};
_httpsv.OnError += (sender, e) =>
@ -54,19 +54,5 @@ namespace Example3
response.StatusCode = (int)HttpStatusCode.NotFound;
}
private static void onResponse(HttpListenerContext context)
{
var req = context.Request;
var res = context.Response;
if (req.HttpMethod == "GET")
{
onGet(req, res);
return;
}
res.StatusCode = (int)HttpStatusCode.MethodNotAllowed;
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -67,6 +67,7 @@ namespace WebSocketSharp
{
if (value < 0)
throw new ArgumentOutOfRangeException("value");
byte b = (byte)value;
dest.Add(b);
return b == Convert.ToByte(c);

View File

@ -67,9 +67,9 @@ namespace WebSocketSharp.Server {
var prefix = String.Format(
"http{0}://*:{1}/", _port == 443 ? "s" : String.Empty, _port);
_listener.Prefixes.Add(prefix);
_rootPath = ConfigurationManager.AppSettings["RootPath"];
_wsPath = wsPath.ToUri();
_wsServer = new WebSocketServer<T>();
configureFromConfigFile();
}
#endregion
@ -84,8 +84,16 @@ namespace WebSocketSharp.Server {
#region Events
public event EventHandler<ResponseEventArgs> OnConnect;
public event EventHandler<ResponseEventArgs> OnDelete;
public event EventHandler<ErrorEventArgs> OnError;
public event EventHandler<ResponseEventArgs> OnResponse;
public event EventHandler<ResponseEventArgs> OnGet;
public event EventHandler<ResponseEventArgs> OnHead;
public event EventHandler<ResponseEventArgs> OnOptions;
public event EventHandler<ResponseEventArgs> OnPatch;
public event EventHandler<ResponseEventArgs> OnPost;
public event EventHandler<ResponseEventArgs> OnPut;
public event EventHandler<ResponseEventArgs> OnTrace;
#endregion
@ -113,23 +121,25 @@ namespace WebSocketSharp.Server {
}
}
private void configureFromConfigFile()
{
_rootPath = ConfigurationManager.AppSettings["RootPath"];
}
private void respond(HttpListenerContext context)
{
WaitCallback respondCb = (state) =>
{
try
{
var req = context.Request;
var res = context.Response;
if (req.IsWebSocketRequest)
if (context.Request.IsWebSocketRequest)
{
upgradeToWebSocket(context);
}
else
{
OnResponse.Emit(this, new ResponseEventArgs(context));
res.Close();
respondToClient(context);
context.Response.Close();
}
}
catch (Exception ex)
@ -140,6 +150,69 @@ namespace WebSocketSharp.Server {
ThreadPool.QueueUserWorkItem(respondCb);
}
private void respondToClient(HttpListenerContext context)
{
var req = context.Request;
var res = context.Response;
var eventArgs = new ResponseEventArgs(context);
if (req.HttpMethod == "GET" && OnGet != null)
{
OnGet(this, eventArgs);
return;
}
if (req.HttpMethod == "HEAD" && OnHead != null)
{
OnHead(this, eventArgs);
return;
}
if (req.HttpMethod == "POST" && OnPost != null)
{
OnPost(this, eventArgs);
return;
}
if (req.HttpMethod == "PUT" && OnPut != null)
{
OnPut(this, eventArgs);
return;
}
if (req.HttpMethod == "DELETE" && OnDelete != null)
{
OnDelete(this, eventArgs);
return;
}
if (req.HttpMethod == "OPTIONS" && OnOptions != null)
{
OnOptions(this, eventArgs);
return;
}
if (req.HttpMethod == "TRACE" && OnTrace != null)
{
OnTrace(this, eventArgs);
return;
}
if (req.HttpMethod == "CONNECT" && OnConnect != null)
{
OnConnect(this, eventArgs);
return;
}
if (req.HttpMethod == "PATCH" && OnPatch != null)
{
OnPatch(this, eventArgs);
return;
}
res.StatusCode = (int)HttpStatusCode.NotImplemented;
}
private void startAcceptRequestThread()
{
_acceptRequestThread = new Thread(new ThreadStart(acceptRequest));

View File

@ -33,11 +33,13 @@ namespace WebSocketSharp.Server {
public class ResponseEventArgs : EventArgs
{
public HttpListenerContext Context { get; private set; }
public HttpListenerRequest Request { get; private set; }
public HttpListenerResponse Response { get; private set; }
public ResponseEventArgs(HttpListenerContext context)
{
Context = context;
Request = context.Request;
Response = context.Response;
}
}
}

View File

@ -677,9 +677,9 @@ namespace WebSocketSharp
{
close(CloseStatusCode.TOO_BIG, ex.Message);
}
catch (Exception ex)
catch (Exception)
{
close(CloseStatusCode.ABNORMAL, ex.Message);
close(CloseStatusCode.ABNORMAL, "An exception has been raised.");
}
}
@ -1075,7 +1075,7 @@ namespace WebSocketSharp
catch (Exception ex)
{
error(ex.Message);
close(CloseStatusCode.HANDSHAKE_FAILURE, ex.Message);
close(CloseStatusCode.HANDSHAKE_FAILURE, "An exception has been raised.");
}
}

View File

@ -38,7 +38,7 @@ namespace WebSocketSharp
static WsReceivedTooBigMessageException()
{
_defaultMessage = String.Format(
"Client received a payload data bigger than the allowable value({0} bytes).", PayloadData.MaxLength);
"Size of received payload data is bigger than the allowable value({0} bytes).", PayloadData.MaxLength);
}
public WsReceivedTooBigMessageException()

Binary file not shown.