Stripes

Add "length" property to StreamingResolution

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: Release 1.5.1
  • Fix Version/s: Release 1.5.2
  • Component/s: None
  • Labels:
    None

Description

StreamingResolution already has a filename property which can be helpful for browser "Save As" dialogs. I suggest adding a "length" property - to match java.io.File#length(). This would be used as the Content-Disposition "size" param.

In addition to filename and size, the Content-Disposition RFC (http://www.ietf.org/rfc/rfc2183.txt) names a few other parameters that might be useful: creation-date, modification-date and read-date, however only lastModified is available on java.io.File.

Adding the size property might result in more informative download progress bars. I have not tested this yet.

I tested adding the last-modified parameter, in the hope that the resulting downloaded file would inherit that timestamp, however for the only browser I tested (Safari) this was not honored. It may be honored by other browsers.

Activity

Hide
Chris Herron added a comment - 10/Jun/08 3:43 PM

Uploading patch with example code for adding the size and last-modified Content-Disposition params.

The exposed properties are named and typed to match java.io.File.

Should probably ditch the lastModified property unless you find a good reason to support it. Left it in just in case.

Implementation alternative: aporter suggested keeping the external properties, but having an internal map. This is not worthwhile if you only go with adding the size property.

Show
Chris Herron added a comment - 10/Jun/08 3:43 PM Uploading patch with example code for adding the size and last-modified Content-Disposition params. The exposed properties are named and typed to match java.io.File. Should probably ditch the lastModified property unless you find a good reason to support it. Left it in just in case. Implementation alternative: aporter suggested keeping the external properties, but having an internal map. This is not worthwhile if you only go with adding the size property.
Hide
Chris Herron added a comment - 06/Apr/09 3:35 PM

Alternatively, it would be useful to separate the header-setting code within StreamingResolution#execute into its own non-final method so that we could add whatever we need by extending the class. Or both

Show
Chris Herron added a comment - 06/Apr/09 3:35 PM Alternatively, it would be useful to separate the header-setting code within StreamingResolution#execute into its own non-final method so that we could add whatever we need by extending the class. Or both
Hide
Chris Herron added a comment - 10/Apr/09 12:47 PM

Added updated patch (#2). I have found that the content-disposition header is not effective in reporting filename, size, last-modified values for direct downloads of files. The means that for files downloaded via StreamingResolution:

  • Browsers don't show accurate progress indicators
  • File caching (e.g. Java Web Start) behavior is erratic

So I have updated the patch to include:

  • An "attachment" flag that toggles between the original content-disposition header behavior (default) and setting response headers for a "direct" download.
  • Added a protected non-final method applyHeaders, which separates the header-setting code from the streaming execution call. This allows developers to override the header behavior to aid extensibility. Tim may have had a reason for making the execute method final, but its not apparent to me that this separation has any downsides.

To use the new header behavior, you need to set the attachment flag to false:

return new StreamingResolution(foo).setAttachment(false)

Show
Chris Herron added a comment - 10/Apr/09 12:47 PM Added updated patch (#2). I have found that the content-disposition header is not effective in reporting filename, size, last-modified values for direct downloads of files. The means that for files downloaded via StreamingResolution:
  • Browsers don't show accurate progress indicators
  • File caching (e.g. Java Web Start) behavior is erratic
So I have updated the patch to include:
  • An "attachment" flag that toggles between the original content-disposition header behavior (default) and setting response headers for a "direct" download.
  • Added a protected non-final method applyHeaders, which separates the header-setting code from the streaming execution call. This allows developers to override the header behavior to aid extensibility. Tim may have had a reason for making the execute method final, but its not apparent to me that this separation has any downsides.
To use the new header behavior, you need to set the attachment flag to false: return new StreamingResolution(foo).setAttachment(false)
Hide
Chris Herron added a comment - 10/Apr/09 1:00 PM

To test this, create an ActionBean with two handler methods, each that streams the same file (preferably a large file).
Handler method 1 should return the file with setAttachment(true) (default).
Handler method 2 should return the file with setAttachment(false)

Hit each of the corresponding URLs using a browser and observe:

  • Download progress indicator information
  • Saved file timestamp

Can also compare the headers using curl:

curl -D headers1.out http://localhost:8080/action/download/method1
curl -D headers2.out http://localhost:8080/action/download/method2

Show
Chris Herron added a comment - 10/Apr/09 1:00 PM To test this, create an ActionBean with two handler methods, each that streams the same file (preferably a large file). Handler method 1 should return the file with setAttachment(true) (default). Handler method 2 should return the file with setAttachment(false) Hit each of the corresponding URLs using a browser and observe:
  • Download progress indicator information
  • Saved file timestamp
Can also compare the headers using curl: curl -D headers1.out http://localhost:8080/action/download/method1 curl -D headers2.out http://localhost:8080/action/download/method2
Hide
Ben Gunter added a comment - 19/Oct/09 12:35 PM

Applied the second patch and tweaked it a little bit. Committed for 1.5.2 (r1170) and 1.6 (r1171).

Show
Ben Gunter added a comment - 19/Oct/09 12:35 PM Applied the second patch and tweaked it a little bit. Committed for 1.5.2 (r1170) and 1.6 (r1171).

People

Vote (0)
Watch (1)

Dates

  • Created:
    10/Jun/08 3:22 PM
    Updated:
    04/Jan/11 2:59 PM
    Resolved:
    19/Oct/09 12:35 PM