Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
spring-projects-issues opened this issue Dec 19, 2017 · 0 comments
Labels
in: test Issues in the test module type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 19, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant