Bug 1190298 - [GSS] (6.4.z) Impossible to set the content type HTTP header in a 204 response
Summary: [GSS] (6.4.z) Impossible to set the content type HTTP header in a 204 response
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: Web
Version: 6.3.3
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: CR2
: EAP 6.4.1
Assignee: Enrique Gonzalez Martinez
QA Contact: Radim Hatlapatka
URL:
Whiteboard:
Depends On:
Blocks: 1188828 eap641-payload
TreeView+ depends on / blocked
 
Reported: 2015-02-06 23:22 UTC by William Antônio
Modified: 2019-03-22 07:37 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-17 09:57:04 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
patch for 7.5.7 jbossweb (invalid) (1.33 KB, patch)
2015-03-06 12:32 UTC, Enrique Gonzalez Martinez
no flags Details | Diff
patch jboss 7.5.x (2.21 KB, patch)
2015-03-18 11:40 UTC, Enrique Gonzalez Martinez
egonzale: review? (rmaucher)
Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker WFLY-4535 0 Major Closed Impossible to set the content type HTTP header in a 204 response 2018-03-06 09:54:31 UTC

Description William Antônio 2015-02-06 23:22:37 UTC
Description of problem:

When we return return 204 from a WEB application deployed in JBoss EAP, it is not possible to set the HTTP Header Content-Type. It is always removed from the HTTP response

Version-Release number of selected component (if applicable):


How reproducible:

Always.

Steps to Reproduce:
1. Create some WEB resource that will returns 204. Let's say a JAX-RS resource:

	@GET
	@Path("204")
	@Produces(MediaType.APPLICATION_JSON)
	public Response return204(@Context HttpServletResponse resp) {
		resp.setContentType("application/json");
		return Response.status(204).build();
	}

2. We can also try to set the content type using a valve:

public class MyCustomValve extends ValveBase {

	@Override
	public void invoke(Request req, Response rep) throws IOException,
			ServletException {
		getNext().invoke(req, rep);
		rep.setContentType("Application/json");
	}

}

Actual results:

There is not Content Type header in the response.


Expected results:

A content type header in the response with Application/JSON value.

Additional info:
It seems to be a bug which was fixed in Tomcat 7.0.40(http://tomcat.apache.org/tomcat-7.0-doc/changelog.html#Tomcat_7.0.40_%28markt%29), but there is no open ticket for it. Two commits fixed it:

$ git show d3d8c9db6279f5439ee8393549fec29d5b88ec49
commit d3d8c9db6279f5439ee8393549fec29d5b88ec49
Author: Mark Emlyn David Thomas <markt>
Date:   Sat May 4 21:49:16 2013 +0000

    204 responses are permitted entity headers
    
    git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk@1479189 13f79535-47bb-0310-9956-ffa450edef68

diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
index 8daac7a..3ce2165 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
@@ -1378,7 +1378,8 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
         }
 
         MimeHeaders headers = response.getMimeHeaders();
-        if (!entityBody) {
+        // A SC_NO_CONTENT (204) response may include entity headers
+        if (!entityBody && statusCode != 204) {
             response.setContentLength(-1);
         } else {
             String contentType = response.getContentType();
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4d1d933..4652940 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -90,6 +90,10 @@
         exception does not cause remaining checks to be skipped. Based on a
         patch by NateC.
       </fix>
+      <fix>
+        Allow 204 responses (no content) to include entity headers as required
+        by RFC2616. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">

and

$ git show edf6d758d5f411da8e6c579265d4e1e2daf77b8c
commit edf6d758d5f411da8e6c579265d4e1e2daf77b8c
Author: Mark Emlyn David Thomas <markt>
Date:   Sun May 5 07:47:28 2013 +0000

    Deal properly with 204 responses
    Fix an irritating warning
    
    git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc7.0.x/trunk@1479249 13f79535-47bb-0310-9956-ffa450edef68

diff --git a/java/org/apache/coyote/http11/AbstractHttp11Processor.java b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
index 3ce2165..3c5a194 100644
--- a/java/org/apache/coyote/http11/AbstractHttp11Processor.java
+++ b/java/org/apache/coyote/http11/AbstractHttp11Processor.java
@@ -816,7 +816,6 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
             InputFilter savedBody = new SavedRequestInputFilter(body);
             savedBody.setRequest(request);
 
-            @SuppressWarnings("unchecked")
             AbstractInputBuffer<S> internalBuffer = (AbstractInputBuffer<S>)
                 request.getInputBuffer();
             internalBuffer.addActiveFilter(savedBody);
@@ -1378,10 +1377,11 @@ public abstract class AbstractHttp11Processor<S> extends AbstractProcessor<S> {
         }
 
         MimeHeaders headers = response.getMimeHeaders();
-        // A SC_NO_CONTENT (204) response may include entity headers
-        if (!entityBody && statusCode != 204) {
+        if (!entityBody) {
             response.setContentLength(-1);
-        } else {
+        }
+        // A SC_NO_CONTENT response may include entity headers
+        if (entityBody || statusCode == 204) {
             String contentType = response.getContentType();
             if (contentType != null) {
                 headers.setValue("Content-Type").setString(contentType);

Comment 2 Enrique Gonzalez Martinez 2015-03-06 12:32:51 UTC
Created attachment 998782 [details]
patch for 7.5.7 jbossweb (invalid)

Comment 3 Enrique Gonzalez Martinez 2015-03-18 11:40:20 UTC
Created attachment 1003159 [details]
patch jboss 7.5.x

Attached Patch 7.5.x for this BZ.

Comment 4 Rémy Maucherat 2015-03-23 13:38:04 UTC
To be complete: r2599

Comment 6 JBoss JIRA Server 2015-04-20 07:12:11 UTC
Bartosz Baranowski <bbaranow> updated the status of jira WFLY-4535 to Closed

Comment 7 Enrique Gonzalez Martinez 2015-04-20 07:54:15 UTC
Just to clarify: Upstream fix is not required. undertow return the right headers.

Comment 9 Rostislav Svoboda 2015-04-23 14:20:19 UTC
qa_acking, thank you for the test

Comment 10 Radim Hatlapatka 2015-05-14 14:20:33 UTC
Verified with EAP 6.4.1.CP.CR2

Comment 11 Petr Penicka 2017-01-17 09:57:04 UTC
Retroactively bulk-closing issues from released EAP 6.4 cummulative patches.


Note You need to log in before you can comment on or make changes to this bug.