Polishing
This commit is contained in:
parent
1e4c10cef1
commit
dd6cb1b728
|
@ -236,9 +236,9 @@ public final class ContentDisposition {
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.filename);
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.charset);
|
||||||
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.size);
|
||||||
result = 31 * result + (this.creationDate != null ? this.creationDate.hashCode() : 0);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.creationDate);
|
||||||
result = 31 * result + (this.modificationDate != null ? this.modificationDate.hashCode() : 0);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.modificationDate);
|
||||||
result = 31 * result + (this.readDate != null ? this.readDate.hashCode() : 0);
|
result = 31 * result + ObjectUtils.nullSafeHashCode(this.readDate);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,8 @@ public sealed interface HttpStatusCode extends Serializable permits DefaultHttpS
|
||||||
* positive number
|
* positive number
|
||||||
*/
|
*/
|
||||||
static HttpStatusCode valueOf(int code) {
|
static HttpStatusCode valueOf(int code) {
|
||||||
Assert.isTrue(code >= 100 && code <= 999, () -> "Code '" + code + "' should be a three-digit positive integer");
|
Assert.isTrue(code >= 100 && code <= 999,
|
||||||
|
() -> "Status code '" + code + "' should be a three-digit positive integer");
|
||||||
HttpStatus status = HttpStatus.resolve(code);
|
HttpStatus status = HttpStatus.resolve(code);
|
||||||
if (status != null) {
|
if (status != null) {
|
||||||
return status;
|
return status;
|
||||||
|
|
|
@ -115,9 +115,9 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
||||||
return setStatusCode(statusCode != null ? HttpStatusCode.valueOf(statusCode) : null);
|
return setStatusCode(statusCode != null ? HttpStatusCode.valueOf(statusCode) : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
@Deprecated
|
|
||||||
public Integer getRawStatusCode() {
|
public Integer getRawStatusCode() {
|
||||||
return this.statusCode != null ? this.statusCode.value() : null;
|
return this.statusCode != null ? this.statusCode.value() : null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,8 +67,8 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
|
||||||
* @since 5.2.4
|
* @since 5.2.4
|
||||||
* @deprecated as of 6.0, in favor of {@link #getStatusCode()}
|
* @deprecated as of 6.0, in favor of {@link #getStatusCode()}
|
||||||
*/
|
*/
|
||||||
@Nullable
|
|
||||||
@Deprecated(since = "6.0")
|
@Deprecated(since = "6.0")
|
||||||
|
@Nullable
|
||||||
default Integer getRawStatusCode() {
|
default Integer getRawStatusCode() {
|
||||||
HttpStatusCode httpStatus = getStatusCode();
|
HttpStatusCode httpStatus = getStatusCode();
|
||||||
return (httpStatus != null ? httpStatus.value() : null);
|
return (httpStatus != null ? httpStatus.value() : null);
|
||||||
|
|
|
@ -25,20 +25,22 @@ import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||||
|
import static org.springframework.http.ContentDisposition.parse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link ContentDisposition}
|
* Unit tests for {@link ContentDisposition}.
|
||||||
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
*/
|
*/
|
||||||
class ContentDispositionTests {
|
class ContentDispositionTests {
|
||||||
|
|
||||||
private static DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
|
private static final DateTimeFormatter formatter = DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
void parse() {
|
@Test
|
||||||
|
void parseFilenameQuoted() {
|
||||||
assertThat(parse("form-data; name=\"foo\"; filename=\"foo.txt\"; size=123"))
|
assertThat(parse("form-data; name=\"foo\"; filename=\"foo.txt\"; size=123"))
|
||||||
.isEqualTo(ContentDisposition.formData()
|
.isEqualTo(ContentDisposition.formData()
|
||||||
.name("foo")
|
.name("foo")
|
||||||
|
@ -168,8 +170,8 @@ class ContentDispositionTests {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
void parseWithExtraSemicolons() {
|
void parseWithExtraSemicolons() {
|
||||||
assertThat(parse("form-data; name=\"foo\";; ; filename=\"foo.txt\"; size=123"))
|
assertThat(parse("form-data; name=\"foo\";; ; filename=\"foo.txt\"; size=123"))
|
||||||
.isEqualTo(ContentDisposition.formData()
|
.isEqualTo(ContentDisposition.formData()
|
||||||
|
@ -179,8 +181,8 @@ class ContentDispositionTests {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
void parseDates() {
|
void parseDates() {
|
||||||
ZonedDateTime creationTime = ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter);
|
ZonedDateTime creationTime = ZonedDateTime.parse("Mon, 12 Feb 2007 10:15:30 -0500", formatter);
|
||||||
ZonedDateTime modificationTime = ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter);
|
ZonedDateTime modificationTime = ZonedDateTime.parse("Tue, 13 Feb 2007 10:15:30 -0500", formatter);
|
||||||
|
@ -198,8 +200,8 @@ class ContentDispositionTests {
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
void parseIgnoresInvalidDates() {
|
void parseIgnoresInvalidDates() {
|
||||||
ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter);
|
ZonedDateTime readTime = ZonedDateTime.parse("Wed, 14 Feb 2007 10:15:30 -0500", formatter);
|
||||||
|
|
||||||
|
@ -228,13 +230,8 @@ class ContentDispositionTests {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> parse("foo;bar"));
|
assertThatIllegalArgumentException().isThrownBy(() -> parse("foo;bar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ContentDisposition parse(String input) {
|
|
||||||
return ContentDisposition.parse(input);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@Test
|
||||||
void format() {
|
void format() {
|
||||||
assertThat(
|
assertThat(
|
||||||
ContentDisposition.formData()
|
ContentDisposition.formData()
|
||||||
|
@ -268,12 +265,9 @@ class ContentDispositionTests {
|
||||||
|
|
||||||
@Test // gh-24220
|
@Test // gh-24220
|
||||||
void formatWithFilenameWithQuotes() {
|
void formatWithFilenameWithQuotes() {
|
||||||
|
|
||||||
BiConsumer<String, String> tester = (input, output) -> {
|
BiConsumer<String, String> tester = (input, output) -> {
|
||||||
|
|
||||||
assertThat(ContentDisposition.formData().filename(input).build().toString())
|
assertThat(ContentDisposition.formData().filename(input).build().toString())
|
||||||
.isEqualTo("form-data; filename=\"" + output + "\"");
|
.isEqualTo("form-data; filename=\"" + output + "\"");
|
||||||
|
|
||||||
assertThat(ContentDisposition.formData().filename(input, StandardCharsets.US_ASCII).build().toString())
|
assertThat(ContentDisposition.formData().filename(input, StandardCharsets.US_ASCII).build().toString())
|
||||||
.isEqualTo("form-data; filename=\"" + output + "\"");
|
.isEqualTo("form-data; filename=\"" + output + "\"");
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue