|
|
@@ -36,6 +36,44 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private string BuildAbsolute( |
|
|
|
string scheme, |
|
|
|
HostString host, |
|
|
|
PathString pathBase = new PathString(), |
|
|
|
PathString path = new PathString(), |
|
|
|
QueryString query = new QueryString(), |
|
|
|
FragmentString fragment = new FragmentString()) |
|
|
|
{ |
|
|
|
if (scheme == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(scheme)); |
|
|
|
} |
|
|
|
|
|
|
|
var combinedPath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/"; |
|
|
|
|
|
|
|
var encodedHost = host.ToString(); |
|
|
|
var encodedQuery = query.ToString(); |
|
|
|
var encodedFragment = fragment.ToString(); |
|
|
|
|
|
|
|
// PERF: Calculate string length to allocate correct buffer size for StringBuilder. |
|
|
|
var length = scheme.Length + SchemeDelimiter.Length + encodedHost.Length |
|
|
|
+ combinedPath.Length + encodedQuery.Length + encodedFragment.Length; |
|
|
|
|
|
|
|
return new StringBuilder(length) |
|
|
|
.Append(scheme) |
|
|
|
.Append(SchemeDelimiter) |
|
|
|
.Append(encodedHost) |
|
|
|
.Append(combinedPath) |
|
|
|
.Append(encodedQuery) |
|
|
|
.Append(encodedFragment) |
|
|
|
.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
private string GetEncodedUrl(HttpRequest request) |
|
|
|
{ |
|
|
|
return BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString); |
|
|
|
} |
|
|
|
|
|
|
|
private async Task<HttpContent> MapContent(HttpRequest request) |
|
|
|
{ |
|
|
|
if (request.Body == null) |
|
|
@@ -64,7 +102,6 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy |
|
|
|
{ |
|
|
|
foreach (var header in request.Headers) |
|
|
|
{ |
|
|
|
//todo get rid of if.. |
|
|
|
if (IsSupportedHeader(header)) |
|
|
|
{ |
|
|
|
requestMessage.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); |
|
|
@@ -88,60 +125,5 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy |
|
|
|
{ |
|
|
|
return !_unsupportedHeaders.Contains(header.Key.ToLower()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Combines the given URI components into a string that is properly encoded for use in HTTP headers. |
|
|
|
/// Note that unicode in the HostString will be encoded as punycode. |
|
|
|
/// </summary> |
|
|
|
/// <param name="scheme">http, https, etc.</param> |
|
|
|
/// <param name="host">The host portion of the uri normally included in the Host header. This may include the port.</param> |
|
|
|
/// <param name="pathBase">The first portion of the request path associated with application root.</param> |
|
|
|
/// <param name="path">The portion of the request path that identifies the requested resource.</param> |
|
|
|
/// <param name="query">The query, if any.</param> |
|
|
|
/// <param name="fragment">The fragment, if any.</param> |
|
|
|
/// <returns></returns> |
|
|
|
public string BuildAbsolute( |
|
|
|
string scheme, |
|
|
|
HostString host, |
|
|
|
PathString pathBase = new PathString(), |
|
|
|
PathString path = new PathString(), |
|
|
|
QueryString query = new QueryString(), |
|
|
|
FragmentString fragment = new FragmentString()) |
|
|
|
{ |
|
|
|
if (scheme == null) |
|
|
|
{ |
|
|
|
throw new ArgumentNullException(nameof(scheme)); |
|
|
|
} |
|
|
|
|
|
|
|
var combinedPath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/"; |
|
|
|
|
|
|
|
var encodedHost = host.ToString(); |
|
|
|
var encodedQuery = query.ToString(); |
|
|
|
var encodedFragment = fragment.ToString(); |
|
|
|
|
|
|
|
// PERF: Calculate string length to allocate correct buffer size for StringBuilder. |
|
|
|
var length = scheme.Length + SchemeDelimiter.Length + encodedHost.Length |
|
|
|
+ combinedPath.Length + encodedQuery.Length + encodedFragment.Length; |
|
|
|
|
|
|
|
return new StringBuilder(length) |
|
|
|
.Append(scheme) |
|
|
|
.Append(SchemeDelimiter) |
|
|
|
.Append(encodedHost) |
|
|
|
.Append(combinedPath) |
|
|
|
.Append(encodedQuery) |
|
|
|
.Append(encodedFragment) |
|
|
|
.ToString(); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
|
/// Returns the combined components of the request URL in a fully escaped form suitable for use in HTTP headers |
|
|
|
/// and other HTTP operations. |
|
|
|
/// </summary> |
|
|
|
/// <param name="request">The request to assemble the uri pieces from.</param> |
|
|
|
/// <returns></returns> |
|
|
|
public string GetEncodedUrl(HttpRequest request) |
|
|
|
{ |
|
|
|
return BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString); |
|
|
|
} |
|
|
|
} |
|
|
|
} |