jersey
  1. jersey
  2. JERSEY-953

204 No Content response includes a Content-Type header

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.11
    • Fix Version/s: 1.18, 2.0
    • Component/s: core
    • Labels:
      None

      Description

      Given a resource class like this:

      ExampleResource.java
      @Path("/example")
      @Produces(MediaType.APPLICATION_JSON)
      public class ExampleResource {
          @GET
          public String get() {
              return "example";
          }
      
          @PUT
          public void put() {
      
          }
      }
      

      PUT requests return a 204 No Content response, but also includes a Content-Type header:

      $ curl -v -XPUT http://localhost:8080/example
      * About to connect() to localhost port 8080 (#0)
      *   Trying ::1... connected
      > PUT /example HTTP/1.1
      > User-Agent: curl/7.23.1 (x86_64-apple-darwin11.2.0) libcurl/7.23.1 OpenSSL/1.0.0f zlib/1.2.5 libidn/1.22
      > Host: localhost:8080
      > Accept: */*
      > 
      < HTTP/1.1 204 No Content
      < Date: Wed, 01 Feb 2012 20:25:28 GMT
      < Content-Type: application/json
      < 
      * Connection #0 to host localhost left intact
      * Closing connection #0
      

      The fact that a Content-Type is specified for a response which cannot have content confuses some clients.

      Moving the @Produces annotation to just the methods which actually return content serves as a workaround, but it seems like Jersey should be smart enough to not send invalid headers.

        Activity

        Hide
        kullfar added a comment -

        Hm... even
        return Response.noContent().type((MediaType) null).build();
        doesn't help ;-(

        I thought
        return Response.noContent().build();
        should help already. but no chance!

        Show
        kullfar added a comment - Hm... even return Response.noContent().type((MediaType) null).build(); doesn't help ;-( I thought return Response.noContent().build(); should help already. but no chance!
        Hide
        kullfar added a comment -

        return Response.status(Response.Status.NOT_FOUND).build();
        at the same time produces
        < HTTP/1.1 404 Not Found
        < Content-Length: 0

        without any
        Content-Type

        Show
        kullfar added a comment - return Response.status(Response.Status.NOT_FOUND).build(); at the same time produces < HTTP/1.1 404 Not Found < Content-Length: 0 without any Content-Type
        Hide
        Michal Gajdos added a comment -

        This problem does not occur in Jersey2 so closing as 'Cannot Reproduce'.
        If you need this fixed in Jersey1 feel free to reopen the issue.

        Show
        Michal Gajdos added a comment - This problem does not occur in Jersey2 so closing as 'Cannot Reproduce'. If you need this fixed in Jersey1 feel free to reopen the issue.
        Hide
        codahale added a comment -

        I don't have the privileges to reopen this, I don't think, but I'd like to.

        If you plan on releasing Jersey 1.14, it'd be nice to have a fix for this. I'm glad to hear it's been automatically fixed in 2.0, but even once that's released we'll still be a ways out from migrating all our code to it. In the meantime, we've had to alter some of our APIs to accommodate clients which use the presence of Content-Type as an indicator of the existence of a response entity.

        Show
        codahale added a comment - I don't have the privileges to reopen this, I don't think, but I'd like to. If you plan on releasing Jersey 1.14, it'd be nice to have a fix for this. I'm glad to hear it's been automatically fixed in 2.0, but even once that's released we'll still be a ways out from migrating all our code to it. In the meantime, we've had to alter some of our APIs to accommodate clients which use the presence of Content-Type as an indicator of the existence of a response entity.
        Hide
        Michal Gajdos added a comment -

        Reopening due to the previous comment. Should be fixed in Jersey 1.14.

        Show
        Michal Gajdos added a comment - Reopening due to the previous comment. Should be fixed in Jersey 1.14.
        Hide
        Marek Potociar added a comment -

        Closing the issue.

        Show
        Marek Potociar added a comment - Closing the issue.

          People

          • Assignee:
            Michal Gajdos
            Reporter:
            codahale
          • Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 3 hours
              3h
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 30 minutes Time Not Required
              30m