Fixed HttpServer.cs

This commit is contained in:
sta 2012-09-13 11:18:52 +09:00
parent ce93711cf2
commit 9730e2a9ff
20 changed files with 22 additions and 11 deletions

Binary file not shown.

View File

@ -40,6 +40,7 @@ namespace WebSocketSharp.Server {
#region Fields #region Fields
private Thread _acceptRequestThread; private Thread _acceptRequestThread;
private bool _isWindows;
private HttpListener _listener; private HttpListener _listener;
private int _port; private int _port;
private string _rootPath; private string _rootPath;
@ -62,14 +63,9 @@ namespace WebSocketSharp.Server {
public HttpServer(int port, string wsPath) public HttpServer(int port, string wsPath)
{ {
_listener = new HttpListener(); _port = port;
_port = port; _wsPath = wsPath.ToUri();
var prefix = String.Format( init();
"http{0}://*:{1}/", _port == 443 ? "s" : String.Empty, _port);
_listener.Prefixes.Add(prefix);
_wsPath = wsPath.ToUri();
_wsServer = new WebSocketServer<T>();
configureFromConfigFile();
} }
#endregion #endregion
@ -126,6 +122,23 @@ namespace WebSocketSharp.Server {
_rootPath = ConfigurationManager.AppSettings["RootPath"]; _rootPath = ConfigurationManager.AppSettings["RootPath"];
} }
private void init()
{
_isWindows = false;
_listener = new HttpListener();
_wsServer = new WebSocketServer<T>();
var os = Environment.OSVersion;
if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
_isWindows = true;
var prefix = String.Format(
"http{0}://*:{1}/", _port == 443 ? "s" : String.Empty, _port);
_listener.Prefixes.Add(prefix);
configureFromConfigFile();
}
private bool isUpgrade(HttpListenerRequest request, string value) private bool isUpgrade(HttpListenerRequest request, string value)
{ {
if (!request.Headers.Exists("Upgrade", value)) if (!request.Headers.Exists("Upgrade", value))
@ -257,9 +270,7 @@ namespace WebSocketSharp.Server {
public byte[] GetFile(string path) public byte[] GetFile(string path)
{ {
var filePath = _rootPath + path; var filePath = _rootPath + path;
if (_isWindows)
var os = Environment.OSVersion;
if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
filePath = filePath.Replace("/", "\\"); filePath = filePath.Replace("/", "\\");
if (File.Exists(filePath)) if (File.Exists(filePath))

Binary file not shown.