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,44 +579,39 @@ 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;
}
} }
if (_url == null) {
var scheme = IsWebSocketRequest ? "ws" : "http";
var secure = IsSecureConnection;
if (secure)
scheme += "s";
var colon = host.IndexOf (':'); var colon = host.IndexOf (':');
if (colon > -1) if (colon == -1)
host = host.Substring (0, colon); host = String.Format ("{0}:{1}", host, secure ? 443 : 80);
var scheme = IsWebSocketRequest ? "ws" : "http";
var url = String.Format (
"{0}://{1}:{2}{3}",
IsSecureConnection ? scheme + "s" : scheme,
host,
LocalEndPoint.Port,
path);
var url = String.Format ("{0}://{1}{2}", scheme, host, path);
if (!Uri.TryCreate (url, UriKind.Absolute, out _url)) { if (!Uri.TryCreate (url, UriKind.Absolute, out _url)) {
_context.ErrorMessage = "Invalid request url: " + url; _context.ErrorMessage = "Invalid request url: " + url;
return; return;
} }
}
_queryString = createQueryString (_url.Query); _queryString = createQueryString (_url.Query);