Skip to content

MockHttpServletRequest and MockHttpServletResponse should re-use date patterns / parsers / formatters from HttpHeaders [SPR-16312] #20859

@spring-projects-issues

Description

@spring-projects-issues

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:

1 votes, 3 watchers

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulestatus: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions