Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
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
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
d6a8aa68
Commit
d6a8aa68
authored
Feb 25, 2020
by
杨锐
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor URL
parent
9cacff85
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
28 deletions
+29
-28
RequestInterceptor.java
...quantgroup/tech/brave/interceptor/RequestInterceptor.java
+29
-28
No files found.
brave-spring-boot-starter/src/main/java/cn/quantgroup/tech/brave/interceptor/RequestInterceptor.java
View file @
d6a8aa68
...
...
@@ -6,18 +6,19 @@ import org.springframework.beans.factory.annotation.Value;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.util.
Date
;
import
java.util.
ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
@Slf4j
public
abstract
class
RequestInterceptor
{
//
@Data
//
static class AuthInfoInMemory {
// private static boolean auth
;
//
private static long expiration;
//
}
@Data
static
class
AuthInfoInMemory
{
private
static
List
<
String
>
hosts
=
new
ArrayList
<>()
;
private
static
long
expiration
;
}
protected
static
final
String
AUTH
=
"quant-auth"
;
// 内网
...
...
@@ -25,12 +26,26 @@ public abstract class RequestInterceptor {
List
<
String
>
authHttpList
;
protected
boolean
auth
(
String
host
)
{
// if (authCache()) return true;
if
(
authHttpList
==
null
||
authHttpList
.
isEmpty
())
{
return
false
;
}
boolean
auth
=
authHttpList
.
stream
()
.
map
(
http
->
{
if
(
AuthInfoInMemory
.
hosts
.
isEmpty
()
||
System
.
currentTimeMillis
()
>
AuthInfoInMemory
.
expiration
){
hostsCache
();
}
return
AuthInfoInMemory
.
hosts
.
contains
(
host
);
}
private
void
hostsCache
()
{
AuthInfoInMemory
.
hosts
=
authHttpList
.
stream
()
.
map
(
RequestInterceptor:
:
apply
)
.
filter
(
Optional:
:
isPresent
)
.
map
(
Optional:
:
get
)
.
map
(
URL:
:
getHost
)
.
collect
(
Collectors
.
toList
());
AuthInfoInMemory
.
expiration
=
System
.
currentTimeMillis
()
+
30
*
60
*
60
*
1000
;
}
private
static
Optional
<
URL
>
apply
(
String
http
)
{
URL
url
=
null
;
try
{
url
=
new
URL
(
http
);
...
...
@@ -38,19 +53,5 @@ public abstract class RequestInterceptor {
log
.
error
(
"无效quant.auth.http = 【{}】"
,
http
);
}
return
Optional
.
ofNullable
(
url
);
})
.
filter
(
Optional:
:
isPresent
)
.
anyMatch
(
url
->
url
.
get
().
getHost
().
equals
(
host
));
// buildAuthCache(auth);
return
auth
;
}
// private boolean authCache() {
// return AuthInfoInMemory.auth && System.currentTimeMillis() < AuthInfoInMemory.expiration;
// }
//
// private void buildAuthCache(boolean auth) {
// AuthInfoInMemory.auth = auth;
// AuthInfoInMemory.expiration = System.currentTimeMillis() + 10 * 60 * 60;
// }
}
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