Allow Instant and ZonedDateTime as Last-Modified header.
Issues: SPR-17571
This commit is contained in:
parent
cf7ee0739f
commit
9abd4ed33d
|
@ -1145,6 +1145,22 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||||
setDate(LAST_MODIFIED, lastModified);
|
setDate(LAST_MODIFIED, lastModified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the time the resource was last changed, as specified by the
|
||||||
|
* {@code Last-Modified} header.
|
||||||
|
*/
|
||||||
|
public void setLastModified(Instant lastModified) {
|
||||||
|
setInstant(LAST_MODIFIED, lastModified);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the time the resource was last changed, as specified by the
|
||||||
|
* {@code Last-Modified} header.
|
||||||
|
*/
|
||||||
|
public void setLastModified(ZonedDateTime lastModified) {
|
||||||
|
setZonedDateTime(LAST_MODIFIED, lastModified);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the time the resource was last changed, as specified by the
|
* Return the time the resource was last changed, as specified by the
|
||||||
* {@code Last-Modified} header.
|
* {@code Last-Modified} header.
|
||||||
|
@ -1266,6 +1282,15 @@ public class HttpHeaders implements MultiValueMap<String, String>, Serializable
|
||||||
set(headerName, DATE_FORMATTERS[0].format(date));
|
set(headerName, DATE_FORMATTERS[0].format(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the given date under the given header name after formatting it as a string
|
||||||
|
* using the RFC-1123 date-time formatter. The equivalent of
|
||||||
|
* {@link #set(String, String)} but for date headers.
|
||||||
|
*/
|
||||||
|
public void setInstant(String headerName, Instant date) {
|
||||||
|
setZonedDateTime(headerName, ZonedDateTime.ofInstant(date, GMT));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the given date under the given header name after formatting it as a string
|
* Set the given date under the given header name after formatting it as a string
|
||||||
* using the RFC-1123 date-time formatter. The equivalent of
|
* using the RFC-1123 date-time formatter. The equivalent of
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
package org.springframework.http;
|
package org.springframework.http;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -359,6 +361,24 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||||
*/
|
*/
|
||||||
B lastModified(long lastModified);
|
B lastModified(long lastModified);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the time the resource was last changed, as specified by the
|
||||||
|
* {@code Last-Modified} header.
|
||||||
|
* @param lastModified the last modified date
|
||||||
|
* @return this builder
|
||||||
|
* @see HttpHeaders#setLastModified(long)
|
||||||
|
*/
|
||||||
|
B lastModified(ZonedDateTime lastModified);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the time the resource was last changed, as specified by the
|
||||||
|
* {@code Last-Modified} header.
|
||||||
|
* @param lastModified the last modified date
|
||||||
|
* @return this builder
|
||||||
|
* @see HttpHeaders#setLastModified(long)
|
||||||
|
*/
|
||||||
|
B lastModified(Instant lastModified);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the location of a resource, as specified by the {@code Location} header.
|
* Set the location of a resource, as specified by the {@code Location} header.
|
||||||
* @param location the location
|
* @param location the location
|
||||||
|
@ -495,6 +515,18 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BodyBuilder lastModified(ZonedDateTime date) {
|
||||||
|
this.headers.setLastModified(date);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BodyBuilder lastModified(Instant date) {
|
||||||
|
this.headers.setLastModified(date);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BodyBuilder location(URI location) {
|
public BodyBuilder location(URI location) {
|
||||||
this.headers.setLocation(location);
|
this.headers.setLocation(location);
|
||||||
|
|
Loading…
Reference in New Issue