Fixed HttpServer.cs

master
sta 13 years ago
parent 8e2a1ee1b3
commit 52ceb665fb

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.

@ -49,7 +49,6 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />

Binary file not shown.

@ -1,7 +1,4 @@
using System;
using System.Configuration;
using System.IO;
using System.Text;
using WebSocketSharp;
using WebSocketSharp.Net;
using WebSocketSharp.Server;

Binary file not shown.

Binary file not shown.

@ -126,26 +126,47 @@ namespace WebSocketSharp.Server {
_rootPath = ConfigurationManager.AppSettings["RootPath"];
}
private bool isUpgrade(HttpListenerRequest request, string value)
{
if (!request.Headers.Exists("Upgrade", value))
return false;
if (!request.Headers.Exists("Connection", "Upgrade"))
return false;
return true;
}
private void respond(HttpListenerContext context)
{
WaitCallback respondCb = (state) =>
{
var req = context.Request;
var res = context.Response;
try
{
if (context.Request.IsWebSocketRequest)
if (isUpgrade(req, "websocket"))
{
upgradeToWebSocket(context);
if (req.IsWebSocketRequest)
{
upgradeToWebSocket(context);
return;
}
res.StatusCode = (int)HttpStatusCode.BadRequest;
}
else
{
respondToClient(context);
context.Response.Close();
}
}
catch (Exception ex)
{
OnError.Emit(this, new ErrorEventArgs(ex.Message));
}
res.Close();
};
ThreadPool.QueueUserWorkItem(respondCb);
}
@ -236,6 +257,9 @@ namespace WebSocketSharp.Server {
public byte[] GetFile(string path)
{
var filePath = _rootPath + path;
#if WINDOWS
filePath = filePath.Replace("/", "\\");
#endif
if (File.Exists(filePath))
return File.ReadAllBytes(filePath);

Loading…
Cancel
Save