You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2019/12/07 17:40:53 UTC

[cxf] branch master updated: CXF-8170: Parse HTTP link headers. Adding support for whitespace(s) and more tests

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 056f0f1  CXF-8170: Parse HTTP link headers. Adding support for whitespace(s) and more tests
056f0f1 is described below

commit 056f0f1f845e87575208289765a81344aadc8ef4
Author: reta <dr...@gmail.com>
AuthorDate: Sat Dec 7 12:40:33 2019 -0500

    CXF-8170: Parse HTTP link headers. Adding support for whitespace(s) and more tests
---
 .../org/apache/cxf/jaxrs/impl/ResponseImpl.java    |  2 +-
 .../apache/cxf/jaxrs/impl/ResponseImplTest.java    | 32 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
index f84dc9c..c03800d 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
@@ -65,7 +65,7 @@ import org.apache.cxf.message.MessageUtils;
 
 public final class ResponseImpl extends Response {
 
-    private static final Pattern LINK_DELIMITER = Pattern.compile(",(?=\\<|$)");
+    private static final Pattern LINK_DELIMITER = Pattern.compile(",\\s*(?=\\<|$)");
 
     private StatusType status;
     private Object entity;
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
index ae6d5c6..8b68989 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
@@ -467,6 +467,38 @@ public class ResponseImplTest {
             assertTrue(links.contains(Link.fromUri("http://prev").rel("prev").build()));
         }
     }
+    
+    @Test
+    public void testGetLinksMultipleMultiline() {
+        try (ResponseImpl ri = new ResponseImpl(200)) {
+            MetadataMap<String, Object> meta = new MetadataMap<>();
+            ri.addMetadata(meta);
+            
+            final Message outMessage = createMessage();
+            outMessage.put(Message.REQUEST_URI, "http://localhost");
+            ri.setOutMessage(outMessage);
+
+            Set<Link> links = ri.getLinks();
+            assertTrue(links.isEmpty());
+
+            meta.add(HttpHeaders.LINK, 
+                "</TheBook/chapter2>;\n"
+                + "         rel=\"prev\", \n"
+                + "         </TheBook/chapter4>;\n"
+                + "         rel=\"next\";");
+
+            assertTrue(ri.hasLink("next"));
+            Link next = ri.getLink("next");
+            assertNotNull(next);
+            assertTrue(ri.hasLink("prev"));
+            Link prev = ri.getLink("prev");
+            assertNotNull(prev);
+
+            links = ri.getLinks();
+            assertTrue(links.contains(Link.fromUri("http://localhost/TheBook/chapter4").rel("next").build()));
+            assertTrue(links.contains(Link.fromUri("http://localhost/TheBook/chapter2").rel("prev").build()));
+        }
+    }
 
     public static class StringBean {
         private String header;