public static Uri GetRequestUri(string rawUri, string cookedUriScheme, string cookedUriHost, string cookedUriPath, string cookedUriQuery) { var builder = new HttpListenerRequestUriBuilder(rawUri, cookedUriScheme, cookedUriHost, cookedUriPath, cookedUriQuery); return(builder.Build()); }
internal void FinishInitialization() { var host = UserHostName; if (ProtocolVersion > HttpVersion.Version10 && string.IsNullOrEmpty(host)) { _context.ErrorMessage = "Invalid host name"; return; } Uri rawUri = null; var path = RawUrl.ToLowerInvariant().MaybeUri() && Uri.TryCreate(RawUrl, UriKind.Absolute, out rawUri) ? rawUri.PathAndQuery : RawUrl; if (string.IsNullOrEmpty(host)) { host = UserHostAddress; } if (rawUri != null) { host = rawUri.Host; } var colon = host.IndexOf(':'); if (colon >= 0) { host = host.Substring(0, colon); } // var baseUri = $"{(IsSecureConnection ? "https" : "http")}://{host}:{LocalEndPoint.Port}"; var baseUri = $"http://{host}:{LocalEndPoint.Port}"; if (!Uri.TryCreate(baseUri + path, UriKind.Absolute, out _url)) { _context.ErrorMessage = WebUtility.HtmlEncode("Invalid url: " + baseUri + path); return; } CreateQueryString(_url.Query); // Use reference source HttpListenerRequestUriBuilder to process url. // Fixes #29927 _url = HttpListenerRequestUriBuilder.GetRequestUri(RawUrl, _url); if (!_clSet) { if (string.Compare(HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(HttpMethod, "PUT", StringComparison.OrdinalIgnoreCase) == 0) { return; } } if (string.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0) { _context.Connection.GetResponseStream().InternalWrite(HttpStatus100, 0, HttpStatus100.Length); } }
internal void FinishInitialization() { var host = UserHostName; if (ProtocolVersion > HttpVersion.Version10 && string.IsNullOrEmpty(host)) { _context.ErrorMessage = "Invalid host name"; return; } string path; Uri rawUri = null; if (MaybeUri(RawUrl.ToLowerInvariant()) && Uri.TryCreate(RawUrl, UriKind.Absolute, out rawUri)) { path = rawUri.PathAndQuery; } else { path = RawUrl; } if (string.IsNullOrEmpty(host)) { host = UserHostAddress; } if (rawUri != null) { host = rawUri.Host; } var colon = host.IndexOf(':'); if (colon >= 0) { host = host.Substring(0, colon); } var baseUri = $"{((IsSecureConnection) ? "https" : "http")}://{host}:{LocalEndPoint.Port}"; if (!Uri.TryCreate(baseUri + path, UriKind.Absolute, out _url)) { _context.ErrorMessage = WebUtility.HtmlEncode("Invalid url: " + baseUri + path); return; } CreateQueryString(_url.Query); // Use reference source HttpListenerRequestUriBuilder to process url. // Fixes #29927 _url = HttpListenerRequestUriBuilder.GetRequestUri(RawUrl, _url.Scheme, _url.Authority, _url.LocalPath, _url.Query); #if CHUNKED if (ProtocolVersion >= HttpVersion.Version11) { var tEncoding = Headers["Transfer-Encoding"]; _isChunked = (tEncoding != null && string.Compare(tEncoding, "chunked", StringComparison.OrdinalIgnoreCase) == 0); // 'identity' is not valid! if (tEncoding != null && !_isChunked) { return; } } #endif if (!_isChunked && !_clSet) { if (string.Compare(HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) == 0 || string.Compare(HttpMethod, "PUT", StringComparison.OrdinalIgnoreCase) == 0) { return; } } if (string.Compare(Headers["Expect"], "100-continue", StringComparison.OrdinalIgnoreCase) == 0) { var output = _context.Connection.GetResponseStream(); output.InternalWrite(_100Continue, 0, _100Continue.Length); } }