Dmitry Katsubo opened SPR-16312 and commented
MockHttpServletRequest
has this:
private static final String[] DATE_FORMATS = new String[] {
"EEE, dd MMM yyyy HH:mm:ss zzz",
"EEE, dd-MMM-yy HH:mm:ss zzz",
"EEE MMM dd HH:mm:ss yyyy"
};
MockHttpServletResponse
has this:
private static final String DATE_FORMAT = "EEE, dd MMM yyyy HH:mm:ss zzz";
private static final TimeZone GMT = TimeZone.getTimeZone("GMT");
HttpHeaders
has this:
private static final DateTimeFormatter[] DATE_FORMATTERS = new DateTimeFormatter[] {
DateTimeFormatter.RFC_1123_DATE_TIME,
DateTimeFormatter.ofPattern("EEEE, dd-MMM-yy HH:mm:ss zz", Locale.US),
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss yyyy",Locale.US).withZone(GMT)
};
To optimize above:
* HttpHeaders
is added addDate(String headerName, long date)
method.
* MockHttpServletResponse
delegates setDateHeader(String name, long value)
and addDateHeader(String name, long value)
to HttpHeaders#setDate()
/ HttpHeaders#addDate()
correspondingly.
* MockHttpServletRequest
delegates getDateHeader(String name)
to HttpHeaders#getFirstZonedDateTime(String headerName, boolean rejectInvalid)
.
Affects: 5.0.1
Issue Links: - #16531 MockHttpServletResponse.setDateHeader does not perform date formatting
1 votes, 3 watchers
Comment From: bclozel
MockHttpServletRequest
and MockHttpServletResponse
do not hold HttpHeaders
instances but Map<String, HeaderValueHolder>
. This is by design, as header values can be String
, Date
or Number
. Relying on HttpHeaders
for those operations is not possible as a result.