You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ff...@apache.org on 2018/01/11 03:09:09 UTC

[cxf] branch master updated: [CXF-7607]JAXRS only consider the first Accept header in the request

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

ffang 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 116cb7d  [CXF-7607]JAXRS only consider the first Accept header in the request
116cb7d is described below

commit 116cb7d2df3537b4500b8da7bd261d778dd4c57e
Author: Freeman Fang <fr...@gmail.com>
AuthorDate: Thu Jan 11 11:08:57 2018 +0800

    [CXF-7607]JAXRS only consider the first Accept header in the request
---
 .../org/apache/cxf/transport/http/Headers.java     |  6 ++++++
 .../systest/jaxrs/JAXRSClientServerBookTest.java   | 22 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
index f25b31d..b6dc306 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
@@ -450,6 +450,12 @@ public class Headers {
             }
             for (Enumeration<String> e2 = req.getHeaders(fname); e2.hasMoreElements();) {
                 String val = e2.nextElement();
+                if ("Accept".equals(mappedName) && values.size() > 0) {
+                    //ensure we collapse Accept into first line
+                    String firstAccept = values.get(0);
+                    firstAccept = firstAccept + ", " + val;
+                    values.set(0, firstAccept);
+                }
                 values.add(val);
             }
         }
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 20a08a7..b81dbe6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -2482,6 +2482,28 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
         }
     }
 
+    
+    @Test
+    public void testMutipleAcceptHeader() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/bookstore/booksplain";
+
+        CloseableHttpClient client = HttpClientBuilder.create().build();
+        HttpPost post = new HttpPost(endpointAddress);
+        post.addHeader("Content-Type", "text/plain");
+        post.addHeader("Accept", "text/xml");
+        post.addHeader("Accept", "text/plain");
+        post.setEntity(new StringEntity("12345"));
+
+        try {
+            CloseableHttpResponse response = client.execute(post);
+            assertEquals(200, response.getStatusLine().getStatusCode());
+            assertEquals(EntityUtils.toString(response.getEntity()), "12345");
+        } finally {
+            // Release current connection to the connection pool once you are done
+            post.releaseConnection();
+        }
+    }
     @Test
     public void testDeleteBook() throws Exception {
         String endpointAddress =

-- 
To stop receiving notification emails like this one, please contact
['"commits@cxf.apache.org" <co...@cxf.apache.org>'].