Fix for request url in HttpListenerRequest.cs

This commit is contained in:
sta 2014-05-25 16:29:43 +09:00
parent f85f227a79
commit 74b8bb392c

View File

@ -579,43 +579,38 @@ namespace WebSocketSharp.Net
host = UserHostAddress; host = UserHostAddress;
string path = null; string path = null;
Uri rawUri; if (_rawUrl.StartsWith ("/")) {
if (_rawUrl == "*") {
}
else if (_rawUrl.StartsWith ("/")) {
path = HttpUtility.UrlDecode (_rawUrl); path = HttpUtility.UrlDecode (_rawUrl);
} }
else if (_rawUrl.MaybeUri () && Uri.TryCreate (_rawUrl, UriKind.Absolute, out rawUri)) { else if (_rawUrl.MaybeUri ()) {
host = rawUri.Host; if (!Uri.TryCreate (_rawUrl, UriKind.Absolute, out _url) ||
path = rawUri.PathAndQuery; !(_url.Scheme.StartsWith ("http") || _url.Scheme.StartsWith ("ws"))) {
_context.ErrorMessage = "Invalid request url: " + _rawUrl;
return;
}
}
else if (_rawUrl == "*") {
} }
else { else {
var authority = HttpUtility.UrlDecode (_rawUrl); // As authority form
var slash = authority.IndexOf ('/'); host = HttpUtility.UrlDecode (_rawUrl);
if (slash > -1) {
host = authority.Substring (0, slash);
path = authority.Substring (slash);
}
else {
host = authority;
}
} }
var colon = host.IndexOf (':'); if (_url == null) {
if (colon > -1) var scheme = IsWebSocketRequest ? "ws" : "http";
host = host.Substring (0, colon); var secure = IsSecureConnection;
if (secure)
scheme += "s";
var scheme = IsWebSocketRequest ? "ws" : "http"; var colon = host.IndexOf (':');
var url = String.Format ( if (colon == -1)
"{0}://{1}:{2}{3}", host = String.Format ("{0}:{1}", host, secure ? 443 : 80);
IsSecureConnection ? scheme + "s" : scheme,
host,
LocalEndPoint.Port,
path);
if (!Uri.TryCreate (url, UriKind.Absolute, out _url)) { var url = String.Format ("{0}://{1}{2}", scheme, host, path);
_context.ErrorMessage = "Invalid request url: " + url; if (!Uri.TryCreate (url, UriKind.Absolute, out _url)) {
return; _context.ErrorMessage = "Invalid request url: " + url;
return;
}
} }
_queryString = createQueryString (_url.Query); _queryString = createQueryString (_url.Query);