Fix for pull request #115, added the HttpServer (System.Net.IPAddress, int, bool) constructor
This commit is contained in:
parent
4bc2c4d4f0
commit
c10c9886ef
@ -18,7 +18,8 @@ namespace Example3
|
||||
* with the 'secure' parameter set to true.
|
||||
*/
|
||||
var httpsv = new HttpServer (4649);
|
||||
//httpsv = new HttpServer (4649, true);
|
||||
//var httpsv = new HttpServer (5963, true);
|
||||
//var httpsv = new HttpServer (System.Net.IPAddress.Parse ("127.0.0.1"), 4649, false);
|
||||
#if DEBUG
|
||||
// To change the logging level.
|
||||
httpsv.Log.Level = LogLevel.Trace;
|
||||
|
@ -311,6 +311,8 @@ namespace WebSocketSharp.Net
|
||||
return null;
|
||||
|
||||
var host = uri.Host;
|
||||
var dns = Uri.CheckHostName (host) == UriHostNameType.Dns;
|
||||
|
||||
var port = uri.Port;
|
||||
var path = HttpUtility.UrlDecode (uri.AbsolutePath);
|
||||
var pathSlash = path[path.Length - 1] == '/' ? path : path + "/";
|
||||
@ -323,7 +325,9 @@ namespace WebSocketSharp.Net
|
||||
if (ppath.Length < bestLen)
|
||||
continue;
|
||||
|
||||
if (pref.Host != host || pref.Port != port)
|
||||
var phost = pref.Host;
|
||||
var pdns = Uri.CheckHostName (phost) == UriHostNameType.Dns;
|
||||
if ((dns && pdns && phost != host) || pref.Port != port)
|
||||
continue;
|
||||
|
||||
if (path.StartsWith (ppath) || pathSlash.StartsWith (ppath)) {
|
||||
|
@ -40,6 +40,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Security.Principal;
|
||||
using System.Threading;
|
||||
@ -135,6 +136,49 @@ namespace WebSocketSharp.Server
|
||||
init ("*", port, secure);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="HttpServer"/> class with
|
||||
/// the specified <paramref name="address"/>, <paramref name="port"/>,
|
||||
/// and <paramref name="secure"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// An instance initialized by this constructor listens for the incoming
|
||||
/// connection requests on <paramref name="port"/>.
|
||||
/// </remarks>
|
||||
/// <param name="address">
|
||||
/// A <see cref="System.Net.IPAddress"/> that represents the local IP address of the server.
|
||||
/// </param>
|
||||
/// <param name="port">
|
||||
/// An <see cref="int"/> that represents the port number on which to listen.
|
||||
/// </param>
|
||||
/// <param name="secure">
|
||||
/// A <see cref="bool"/> that indicates providing a secure connection or not.
|
||||
/// (<c>true</c> indicates providing a secure connection.)
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="address"/> is <see langword="null"/>.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// <paramref name="address"/> isn't a local IP address.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="port"/> isn't between 1 and 65535 inclusive.
|
||||
/// </exception>
|
||||
public HttpServer (System.Net.IPAddress address, int port, bool secure)
|
||||
{
|
||||
if (address == null)
|
||||
throw new ArgumentNullException ("address");
|
||||
|
||||
if (!address.IsLocal ())
|
||||
throw new ArgumentException ("Not a local IP address: " + address, "address");
|
||||
|
||||
if (!port.IsPortNumber ())
|
||||
throw new ArgumentOutOfRangeException (
|
||||
"port", "Not between 1 and 65535 inclusive: " + port);
|
||||
|
||||
init (address.ToString (), port, secure);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
Loading…
Reference in New Issue
Block a user