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
ef542010
Commit
ef542010
authored
Sep 24, 2017
by
Savorboard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor dashboard middleware
parent
aa361583
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
18 deletions
+42
-18
CAP.DashboardMiddleware.cs
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
+42
-18
No files found.
src/DotNetCore.CAP/Dashboard/CAP.DashboardMiddleware.cs
View file @
ef542010
...
...
@@ -21,33 +21,57 @@ namespace DotNetCore.CAP
_routes
=
routes
??
throw
new
ArgumentNullException
(
nameof
(
routes
));
}
public
Task
Invoke
(
HttpContext
httpC
ontext
)
public
Task
Invoke
(
HttpContext
c
ontext
)
{
var
context
=
new
CapDashboardContext
(
_storage
,
_options
,
httpContext
)
;
var
findResult
=
_routes
.
FindDispatcher
(
httpContext
.
Request
.
Path
.
Value
)
;
PathString
matchedPath
;
PathString
remainingPath
;
if
(
findResult
==
null
)
if
(
context
.
Request
.
Path
.
StartsWithSegments
(
_options
.
PathMatch
,
out
matchedPath
,
out
remainingPath
)
)
{
return
_next
.
Invoke
(
httpContext
);
}
// Update the path
var
path
=
context
.
Request
.
Path
;
var
pathBase
=
context
.
Request
.
PathBase
;
context
.
Request
.
PathBase
=
pathBase
.
Add
(
matchedPath
);
context
.
Request
.
Path
=
remainingPath
;
foreach
(
var
filter
in
_options
.
Authorization
)
{
if
(!
filter
.
Authorize
(
context
))
try
{
var
isAuthenticated
=
httpContext
.
User
?.
Identity
?.
IsAuthenticated
;
var
dashboardContext
=
new
CapDashboardContext
(
_storage
,
_options
,
context
);
var
findResult
=
_routes
.
FindDispatcher
(
context
.
Request
.
Path
.
Value
);
httpContext
.
Response
.
StatusCode
=
isAuthenticated
==
true
?
(
int
)
HttpStatusCode
.
Forbidden
:
(
int
)
HttpStatusCode
.
Unauthorized
;
if
(
findResult
==
null
)
{
return
_next
.
Invoke
(
context
);
}
return
Task
.
FromResult
(
0
);
}
}
foreach
(
var
filter
in
_options
.
Authorization
)
{
if
(!
filter
.
Authorize
(
dashboardContext
))
{
var
isAuthenticated
=
context
.
User
?.
Identity
?.
IsAuthenticated
;
context
.
Response
.
StatusCode
=
isAuthenticated
==
true
?
(
int
)
HttpStatusCode
.
Forbidden
:
(
int
)
HttpStatusCode
.
Unauthorized
;
return
Task
.
CompletedTask
;
}
}
c
ontext
.
UriMatch
=
findResult
.
Item2
;
dashboardC
ontext
.
UriMatch
=
findResult
.
Item2
;
return
findResult
.
Item1
.
Dispatch
(
context
);
return
findResult
.
Item1
.
Dispatch
(
dashboardContext
);
}
finally
{
context
.
Request
.
PathBase
=
pathBase
;
context
.
Request
.
Path
=
path
;
}
}
else
{
return
_next
(
context
);
}
}
}
}
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