Fix for request url in HttpListenerRequest.cs

master
sta 12 years ago
parent f85f227a79
commit 74b8bb392c

@ -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 {
var authority = HttpUtility.UrlDecode (_rawUrl);
var slash = authority.IndexOf ('/');
if (slash > -1) {
host = authority.Substring (0, slash);
path = authority.Substring (slash);
} }
else { else if (_rawUrl == "*") {
host = authority;
} }
else {
// As authority form
host = HttpUtility.UrlDecode (_rawUrl);
} }
var colon = host.IndexOf (':'); if (_url == null) {
if (colon > -1)
host = host.Substring (0, colon);
var scheme = IsWebSocketRequest ? "ws" : "http"; var scheme = IsWebSocketRequest ? "ws" : "http";
var url = String.Format ( var secure = IsSecureConnection;
"{0}://{1}:{2}{3}", if (secure)
IsSecureConnection ? scheme + "s" : scheme, scheme += "s";
host,
LocalEndPoint.Port,
path);
var colon = host.IndexOf (':');
if (colon == -1)
host = String.Format ("{0}:{1}", host, secure ? 443 : 80);
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);

Loading…
Cancel
Save