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

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit 1c3b7f550c1082c077801daf0399d5b99d8c5e5f
Author: Rene Cordier <rcord...@linagora.com>
AuthorDate: Wed Apr 1 10:34:29 2020 +0700

    JAMES-3092 Using HttpCore library to parse correctly the version parameter 
in accept header
---
 server/protocols/jmap/pom.xml                      |  5 ++++
 .../org/apache/james/jmap/JMAPRoutesHandler.java   | 27 ++++++++++++++--------
 2 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/server/protocols/jmap/pom.xml b/server/protocols/jmap/pom.xml
index 1da1e9e..e7b7e0b 100644
--- a/server/protocols/jmap/pom.xml
+++ b/server/protocols/jmap/pom.xml
@@ -65,6 +65,11 @@
             <artifactId>javax.annotation-api</artifactId>
         </dependency>
         <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.13</version>
+        </dependency>
+        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>jcl-over-slf4j</artifactId>
             <scope>test</scope>
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutesHandler.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutesHandler.java
index 8c094f5..2edb6cc 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutesHandler.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/JMAPRoutesHandler.java
@@ -22,16 +22,18 @@ package org.apache.james.jmap;
 import static io.netty.handler.codec.http.HttpHeaderNames.ACCEPT;
 
 import java.util.Arrays;
-import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Stream;
 
+import org.apache.http.NameValuePair;
+import org.apache.http.message.BasicHeaderValueParser;
+
 import com.google.common.collect.ImmutableSet;
 
 import reactor.netty.http.server.HttpServerRequest;
 
 public class JMAPRoutesHandler {
-    String JMAP_VERSION_HEADER = "jmapVersion=";
+    private static String JMAP_VERSION_HEADER = "jmapVersion";
 
     private final Version version;
     private final Set<JMAPRoutes> routes;
@@ -54,15 +56,22 @@ public class JMAPRoutesHandler {
     }
 
     private Version extractRequestVersionHeader(HttpServerRequest request) {
-        return Optional.ofNullable(request.requestHeaders().get(ACCEPT))
-            .map(s -> s.split(";"))
-            .map(Arrays::stream)
-            .orElse(Stream.of())
-            .map(value -> value.trim().toLowerCase())
-            .filter(value -> 
value.startsWith(JMAP_VERSION_HEADER.toLowerCase()))
-            .map(value -> value.substring(JMAP_VERSION_HEADER.length()))
+        return asVersion(request)
+            .filter(nameValuePair -> 
nameValuePair.getName().equals(JMAP_VERSION_HEADER))
+            .map(NameValuePair::getValue)
             .map(Version::of)
             .findFirst()
             .orElse(Version.DRAFT);
     }
+
+    private Stream<NameValuePair> asVersion(HttpServerRequest request) {
+        return request.requestHeaders()
+            .getAll(ACCEPT)
+            .stream()
+            .flatMap(this::extractValueParameters);
+    }
+
+    private Stream<NameValuePair> extractValueParameters(String value) {
+        return Arrays.stream(BasicHeaderValueParser.parseParameters(value, 
BasicHeaderValueParser.INSTANCE));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org
For additional commands, e-mail: server-dev-h...@james.apache.org

Reply via email to