Added CreateRequestUrl method to HttpUtility

This commit is contained in:
sta
2014-06-01 20:59:38 +09:00
parent a0ca7a8cb8
commit 94bb58f4fc
3 changed files with 52 additions and 85 deletions

View File

@@ -544,40 +544,9 @@ namespace WebSocketSharp.Net
if (noHost)
host = UserHostAddress;
string scheme = null;
string path = null;
if (_uri.StartsWith ("/")) {
path = _uri;
}
else if (_uri.MaybeUri ()) {
Uri uri;
if (!Uri.TryCreate (_uri, UriKind.Absolute, out uri) ||
!(uri.Scheme.StartsWith ("http") || uri.Scheme.StartsWith ("ws"))) {
_context.ErrorMessage = "Invalid request url: " + _uri;
return;
}
scheme = uri.Scheme;
host = uri.Authority;
path = uri.PathAndQuery;
}
else if (_uri == "*") {
}
else {
// As authority form
host = _uri;
}
if (scheme == null)
scheme = (IsWebSocketRequest ? "ws" : "http") + (IsSecureConnection ? "s" : String.Empty);
var colon = host.IndexOf (':');
if (colon == -1)
host = String.Format ("{0}:{1}", host, scheme == "http" || scheme == "ws" ? 80 : 443);
var url = String.Format ("{0}://{1}{2}", scheme, host, path);
if (!Uri.TryCreate (url, UriKind.Absolute, out _url)) {
_context.ErrorMessage = "Invalid request url: " + url;
_url = HttpUtility.CreateRequestUrl (_uri, host, IsWebSocketRequest, IsSecureConnection);
if (_url == null) {
_context.ErrorMessage = "Invalid request url";
return;
}