Skip to content

Commit

Permalink
Return -1 after parse error for Expires header
Browse files Browse the repository at this point in the history
Issue: SPR-10648
  • Loading branch information
rstoyanchev committed Aug 5, 2013
1 parent 9035a97 commit 0f71da5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spring-web/src/main/java/org/springframework/http/HttpHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,20 @@ public void setExpires(long expires) {
}

/**
* Returns the date and time at which the message is no longer valid, as specified by the {@code Expires} header.
* <p>The date is returned as the number of milliseconds since January 1, 1970 GMT. Returns -1 when the date is unknown.
* Returns the date and time at which the message is no longer valid, as specified by
* the {@code Expires} header.
* <p>The date is returned as the number of milliseconds since January 1, 1970 GMT.
* Returns -1 when the date is unknown.
*
* @return the expires value
*/
public long getExpires() {
return getFirstDate(EXPIRES);
try {
return getFirstDate(EXPIRES);
}
catch (IllegalArgumentException ex) {
return -1;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ public void expires() {
assertEquals("Invalid Expires header", "Thu, 18 Dec 2008 10:20:00 GMT", headers.getFirst("expires"));
}

// SPR-10648 (example is from INT-3063)

@Test
public void expiresInvalidDate() {
headers.set("Expires", "-1");
assertEquals(-1, headers.getExpires());
}

@Test
public void ifModifiedSince() {
Calendar calendar = new GregorianCalendar(2008, 11, 18, 11, 20);
Expand Down

0 comments on commit 0f71da5

Please sign in to comment.