Repository navigation
Conversation
|
After more reading, |
|
@rstoyanchev @poutsma I think this PR is ready to be reviewed by one of you before going to master. |
There was a problem hiding this comment.
The Stream API could make this more readable, something like (not tested):
String contentDisposition = getFirst(CONTENT_DISPOSITION);
if (contentDisposition == null) {
return null;
}
return Arrays.stream(StringUtils.tokenizeToStringArray(contentDisposition, ";"))
.skip(1)
.map(part -> StringUtils.tokenizeToStringArray(part, "="))
.filter(pair -> {
List<String> attributeNames = Arrays.asList("filename", "filename*");
return (pair.length == 2 && attributeNames.contains(pair[0]));
})
.map(pair -> {
String value = "";
return new String[] { pair[0], value};
})
.map(pair -> "filename".equals(pair[0]) ? pair[1] : decodeHeaderField(pair[1]))
.findFirst();There was a problem hiding this comment.
It seems Java 8 stream API is not designed to collect successive pair, so I have kept the array based implementation for now, see http://stackoverflow.com/questions/20470010/collect-successive-pairs-from-a-stream.
There was a problem hiding this comment.
This should be a private field, if testing is the only reason, which is the case as far as I can see.
There was a problem hiding this comment.
Also I'm wondering if it's worth having a ContentDisposition representation along the lines of HttpHeaders#getContentDisposition(), such as for example.
There was a problem hiding this comment.
That would extend the scope of this feature, but yes I think that would be a good idea, more future proof than getContentDispositionFilename().
There was a problem hiding this comment.
I have made both encodeHeaderFieldParam() and decodeHeaderFieldParam() private static methods in my last commit.
f6ba1ed to
f6149da
Compare
|
@rstoyanchev I have pushed an updated commit with If we don't have date parsing according to RFC 822 already implemented, I would suggest to wait an eventual user request to implement I have keep an array based parsing instead of the I have made the 2 encode and decode methods private as requested. Could you have another look to this updated PR and send me your feedback if any? |
|
Sorry for the delay. A few last tweaks. Let's make ContentDisposition a top-level type like HttpMethod, MediaType, HttpRange. The parse logic can then be a static method in Content-Disposition following the same pattern as HttpRange. Similarly the setContentDisposition should take a ContentDisposition and the actual logic to format to a String can be in ContentDisposition, again like HttpRange. In other words let's encapsulate all the Content-Disposition related logic inside |
|
No worry, thanks for your feedback, I will update the PR accordingly. |
|
Okay, feel free to commit straight to master after those changes. |
8ba4cea to
055d095
Compare
This commit introduces a new ContentDisposition class designed to parse and generate Content-Disposition header value as defined in RFC 2183. It supports the disposition type and the name, filename (or filename* when encoded according to RFC 5987) and size parameters. This new class is usually used thanks to HttpHeaders#getContentDisposition() and HttpHeaders#setContentDisposition(ContentDisposition). Issue: SPR-14408
|
Merged via 99a8510 |
As requested in SPR-14408, this PR adds a method to get the
filenameparameter of theContent-Dispositionheader.@bclozel I have not yet included support for
filename*encoded headers, because I am not sure we should support this. See this comment for more details. I will not merge this PR before your feedback.