Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
34defa33
Commit
34defa33
authored
Sep 26, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor.
parent
4457e98d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
74 deletions
+52
-74
GatewayProxyMiddleware.cs
...Core.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs
+13
-13
IRequestMapper.Default.cs
...Core.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs
+38
-56
NodePage.cs
src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs
+1
-1
NodePage.cshtml
src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml
+0
-4
No files found.
src/DotNetCore.CAP/Dashboard/GatewayProxy/GatewayProxyMiddleware.cs
View file @
34defa33
...
...
@@ -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
<
string
,
IEnumerable
<
string
>>
httpResponseHeader
)
{
...
...
src/DotNetCore.CAP/Dashboard/GatewayProxy/IRequestMapper.Default.cs
View file @
34defa33
...
...
@@ -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
);
}
}
}
\ No newline at end of file
src/DotNetCore.CAP/Dashboard/Pages/NodePage.cs
View file @
34defa33
...
...
@@ -29,7 +29,7 @@ namespace DotNetCore.CAP.Dashboard.Pages
if
(
_nodes
==
null
)
{
_discoveryProvider
=
RequestServices
.
GetService
<
INodeDiscoveryProvider
>();
_nodes
=
_discoveryProvider
.
GetNodes
().
GetAwaiter
().
GetResult
();
_nodes
=
_discoveryProvider
.
GetNodes
().
GetAwaiter
().
GetResult
();
}
return
_nodes
;
}
...
...
src/DotNetCore.CAP/Dashboard/Pages/NodePage.cshtml
View file @
34defa33
...
...
@@ -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));
//}
}
<div class="row">
<div class="col-md-12">
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment