mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-20 20:59:07 +00:00
Parse RFC 9651-like date headers
RFC 9651 specifies @«timestamp» as a new format for date headers. The Deprecation header as specified in RFC 9745, for example, makes use of it. Make sure this can be parsed using `HttpHeaders#getFirstDate` and `HttpHeaders#getFirstZonedDateTime` Signed-off-by: Raphael Schweikert <any@sabberworm.com>
This commit is contained in:
committed by
Brian Clozel
parent
815911b39c
commit
130b0ec50c
@@ -36,6 +36,9 @@ import java.util.TimeZone;
|
||||
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -654,6 +657,36 @@ class HttpHeadersTests {
|
||||
assertThat(authorization).isEqualTo("Bearer foo");
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource(value = {
|
||||
"@0,0",
|
||||
"@1,1000",
|
||||
"@10,10000",
|
||||
"@-1,-1000",
|
||||
"@1659578233,1659578233000", // Example from RFC
|
||||
"@-62135596800,-62135596800000", // Example from RFC
|
||||
"@253402214400,253402214400000", // Example from RFC
|
||||
})
|
||||
void rfc9651Dates_valid(String value, long timestampMillis) {
|
||||
headers.set("Deprecation", value);
|
||||
assertThat(headers.getFirstDate("Deprecation")).isEqualTo(timestampMillis);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {
|
||||
"@",
|
||||
" @1",
|
||||
"@ 1",
|
||||
"@0000-",
|
||||
"@15+",
|
||||
"@12p",
|
||||
"@0x15",
|
||||
})
|
||||
void rfc9651Dates_invalid(String value) {
|
||||
headers.set("Deprecation", value);
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> headers.getFirstDate("Deprecation"));
|
||||
}
|
||||
|
||||
|
||||
@Nested
|
||||
class MapEntriesTests {
|
||||
|
||||
Reference in New Issue
Block a user