Skip to content

Commit e08a7ec

Browse files
committed
Merge pull request #34223 from remeio
* pr/34223: Polish contribution Polish HttpEntityMethodProcessor Closes gh-34223
2 parents cd1aefa + 24fa9ea commit e08a7ec

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpEntityMethodProcessor.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,8 @@
3333
import org.springframework.http.HttpEntity;
3434
import org.springframework.http.HttpHeaders;
3535
import org.springframework.http.HttpMethod;
36+
import org.springframework.http.HttpStatus;
37+
import org.springframework.http.HttpStatusCode;
3638
import org.springframework.http.ProblemDetail;
3739
import org.springframework.http.RequestEntity;
3840
import org.springframework.http.ResponseEntity;
@@ -239,18 +241,18 @@ else if (returnValue instanceof ProblemDetail detail) {
239241
}
240242

241243
if (httpEntity instanceof ResponseEntity<?> responseEntity) {
242-
int returnStatus = responseEntity.getStatusCode().value();
243-
outputMessage.getServletResponse().setStatus(returnStatus);
244-
if (returnStatus == 200) {
244+
HttpStatusCode returnStatus = responseEntity.getStatusCode();
245+
outputMessage.getServletResponse().setStatus(returnStatus.value());
246+
if (returnStatus.value() == HttpStatus.OK.value()) {
245247
HttpMethod method = inputMessage.getMethod();
246248
if ((HttpMethod.GET.equals(method) || HttpMethod.HEAD.equals(method))
247249
&& isResourceNotModified(inputMessage, outputMessage)) {
248250
outputMessage.flush();
249251
return;
250252
}
251253
}
252-
else if (returnStatus / 100 == 3) {
253-
String location = outputHeaders.getFirst("location");
254+
else if (returnStatus.is3xxRedirection()) {
255+
String location = outputHeaders.getFirst(HttpHeaders.LOCATION);
254256
if (location != null) {
255257
saveFlashAttributes(mavContainer, webRequest, location);
256258
}

0 commit comments

Comments
 (0)