diff --git a/src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs b/src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs index 27f7734..9ea04ac 100644 --- a/src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs +++ b/src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs @@ -86,19 +86,6 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy } } - private bool TryGetRemoteNode(string requestNodeId, out Node node) - { - var nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); - node = nodes.FirstOrDefault(x => x.Id == requestNodeId); - return node != null; - } - - private void SetDownStreamRequestUri(Node node, string requestPath) - { - var uriBuilder = new UriBuilder("http://", node.Address, node.Port, requestPath); - DownstreamRequest.RequestUri = uriBuilder.Uri; - } - public async Task SetResponseOnHttpContext(HttpContext context, HttpResponseMessage response) { foreach (var httpResponseHeader in response.Content.Headers) @@ -131,6 +118,19 @@ namespace DotNetCore.CAP.Dashboard.GatewayProxy } } + private bool TryGetRemoteNode(string requestNodeId, out Node node) + { + var nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); + node = nodes.FirstOrDefault(x => x.Id == requestNodeId); + return node != null; + } + + private void SetDownStreamRequestUri(Node node, string requestPath) + { + var uriBuilder = new UriBuilder("http://", node.Address, node.Port, requestPath); + DownstreamRequest.RequestUri = uriBuilder.Uri; + } + private static void AddHeaderIfDoesntExist(HttpContext context, KeyValuePair> httpResponseHeader) { diff --git a/src/DotNetCore.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs b/src/DotNetCore.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs index e12751c..823b03b 100644 --- a/src/DotNetCore.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs +++ b/src/DotNetCore.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs @@ -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 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()); } - - /// - /// 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. - /// - /// http, https, etc. - /// The host portion of the uri normally included in the Host header. This may include the port. - /// The first portion of the request path associated with application root. - /// The portion of the request path that identifies the requested resource. - /// The query, if any. - /// The fragment, if any. - /// - 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(); - } - - /// - /// Returns the combined components of the request URL in a fully escaped form suitable for use in HTTP headers - /// and other HTTP operations. - /// - /// The request to assemble the uri pieces from. - /// - public string GetEncodedUrl(HttpRequest request) - { - return BuildAbsolute(request.Scheme, request.Host, request.PathBase, request.Path, request.QueryString); - } } } \ No newline at end of file diff --git a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs index 0d79ca3..fd7b4f0 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs +++ b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs @@ -29,7 +29,7 @@ namespace DotNetCore.CAP.Dashboard.Pages if (_nodes == null) { _discoveryProvider = RequestServices.GetService(); - _nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); + _nodes = _discoveryProvider.GetNodes().GetAwaiter().GetResult(); } return _nodes; } diff --git a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml index 2fca094..433c4f6 100644 --- a/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml +++ b/src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml @@ -5,10 +5,6 @@ @inherits RazorPage @{ Layout = new LayoutPage(Strings.NodePage_Title); - //if (CurrentNodeId != null) - //{ - // Session.Set("cap_current_node",System.Text.Encoding.Default.GetBytes(CurrentNodeId)); - //} }