Tapestry
  1. Tapestry
  2. TAPESTRY-1409

Extend StreamResponse to support setting headers in the Response prior to streaming the contents from the InputStream

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 5.0.4
    • Fix Version/s: 5.0.5
    • Component/s: tapestry-core
    • Labels:
      None

      Description

      Currently responses rendered using StreamResponse will display within the browser (depending on content type).
      Sometimes the application would like to be able to save the response as a file instead of displaying in the browser.

      This can be implemented by setting the "content-disposition" header in the response.

      1. TAP-1409.patch
        5 kB
        Ben Sommerville
      2. TAP-1409_2.patch
        5 kB
        Ben Sommerville

        Issue Links

          Activity

          Ben Sommerville created issue -
          Hide
          Ben Sommerville added a comment -

          Patch to StreamResponse & associated classes to allow saving response as attachment.

          Also adds setHeader, setIntHeader to Response interface.

          Show
          Ben Sommerville added a comment - Patch to StreamResponse & associated classes to allow saving response as attachment. Also adds setHeader, setIntHeader to Response interface.
          Ben Sommerville made changes -
          Field Original Value New Value
          Attachment TAP-1409.patch [ 12355225 ]
          Ben Sommerville made changes -
          Link This issue is duplicated by TAPESTRY-1500 [ TAPESTRY-1500 ]
          Hide
          Howard M. Lewis Ship added a comment -

          I haven't looked at the patch yet, but I think the right approach will be to extend StreamResponse with a new method:

          void prepareResponse(Response response);

          And make sure Response includes the necessary setHeader() methods. This will give the StreamResponse implementation the chance to set any headers it wants before the bytestream is sent down.

          To some degree, having the getContentType() method is uncessary (the SR impl could set the content type), but since its so likely that an implementation wouldn't otherwise know to set the content type, I feel it is worth leaving unchanged.

          Show
          Howard M. Lewis Ship added a comment - I haven't looked at the patch yet, but I think the right approach will be to extend StreamResponse with a new method: void prepareResponse(Response response); And make sure Response includes the necessary setHeader() methods. This will give the StreamResponse implementation the chance to set any headers it wants before the bytestream is sent down. To some degree, having the getContentType() method is uncessary (the SR impl could set the content type), but since its so likely that an implementation wouldn't otherwise know to set the content type, I feel it is worth leaving unchanged.
          Hide
          Ben Sommerville added a comment -

          Original patch added explicit asAttachment & getFilename methods to StreamResponse. This worked but was a little specific. I had been thinking of splitting those methods into a separate interface but Howard's approach is much simpler & more elegant.

          New patch adds prepareResponse method to StreamResponse.as per Howard's approach.

          Show
          Ben Sommerville added a comment - Original patch added explicit asAttachment & getFilename methods to StreamResponse. This worked but was a little specific. I had been thinking of splitting those methods into a separate interface but Howard's approach is much simpler & more elegant. New patch adds prepareResponse method to StreamResponse.as per Howard's approach.
          Ben Sommerville made changes -
          Attachment TAP-1409_2.patch [ 12358397 ]
          Howard M. Lewis Ship made changes -
          Assignee Howard M. Lewis Ship [ hlship ]
          Howard M. Lewis Ship made changes -
          Summary Allow StreamResponse to specify browser should save as file, rather than displaying in page. Extend StreamResponse to support setting headers in the Response prior to streaming the contents from the InputStream
          Hide
          Howard M. Lewis Ship added a comment -

          Great patch!

          Show
          Howard M. Lewis Ship added a comment - Great patch!
          Howard M. Lewis Ship made changes -
          Resolution Fixed [ 1 ]
          Status Open [ 1 ] Closed [ 6 ]
          Fix Version/s 5.0.5 [ 12312477 ]
          Mark Thomas made changes -
          Workflow jira [ 12401501 ] Default workflow, editable Closed status [ 12569176 ]
          Mark Thomas made changes -
          Workflow Default workflow, editable Closed status [ 12569176 ] jira [ 12590433 ]

            People

            • Assignee:
              Howard M. Lewis Ship
              Reporter:
              Ben Sommerville
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development