This is an automated email from the ASF dual-hosted git repository.

hefengen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 814243be55 [ISSUE #5416]Optimize logic to avoid "orElse" 
execution,Update VersionTwoExtractor.java (#5415)
814243be55 is described below

commit 814243be55d9efc07bb124b3b7b83974cfe7df8d
Author: ttfont <[email protected]>
AuthorDate: Wed Jan 24 09:23:40 2024 +0800

    [ISSUE #5416]Optimize logic to avoid "orElse" execution,Update 
VersionTwoExtractor.java (#5415)
    
    * Update VersionTwoExtractor.java
    
    Optimize logic to avoid "orElse" execution:
    “.orElse(httpRequest.getHeaders().getFirst(HttpHeaders.AUTHORIZATION));”
    
    * Update VersionTwoExtractor.java
    
    ---------
    
    Co-authored-by: DamonXue <[email protected]>
---
 .../apache/shenyu/plugin/sign/extractor/VersionTwoExtractor.java   | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/extractor/VersionTwoExtractor.java
 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/extractor/VersionTwoExtractor.java
index 44a943b5c2..43f08ec8fb 100644
--- 
a/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/extractor/VersionTwoExtractor.java
+++ 
b/shenyu-plugin/shenyu-plugin-security/shenyu-plugin-sign/src/main/java/org/apache/shenyu/plugin/sign/extractor/VersionTwoExtractor.java
@@ -37,7 +37,7 @@ public class VersionTwoExtractor implements 
SignParameterExtractor {
 
         // use ShenYu-Authorization to avoid conflict with another 
Authorization
         String token = 
Optional.ofNullable(httpRequest.getHeaders().getFirst(Constants.SHENYU_AUTHORIZATION))
-                
.orElse(httpRequest.getHeaders().getFirst(HttpHeaders.AUTHORIZATION));
+                .orElseGet(() -> getDefaultToken(httpRequest));
 
         if (StringUtils.isEmpty(token) || !token.contains(".")) {
             return new SignParameters();
@@ -59,4 +59,9 @@ public class VersionTwoExtractor implements 
SignParameterExtractor {
 
         return signParameters;
     }
+    
+    private String getDefaultToken(final HttpRequest httpRequest) {
+        return httpRequest.getHeaders().getFirst(HttpHeaders.AUTHORIZATION);
+    }
+    
 }

Reply via email to