File tree Expand file tree Collapse file tree 5 files changed +36
-6
lines changed
spring-web/src/main/java/org/springframework/http/server/reactive Expand file tree Collapse file tree 5 files changed +36
-6
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ public boolean setStatusCode(@Nullable HttpStatus status) {
106
106
@ Override
107
107
@ Nullable
108
108
public HttpStatus getStatusCode () {
109
- return ( this .statusCode != null ? HttpStatus .resolve (this .statusCode ) : null ) ;
109
+ return this .statusCode != null ? HttpStatus .resolve (this .statusCode ) : null ;
110
110
}
111
111
112
112
/**
Original file line number Diff line number Diff line change 31
31
import org .springframework .core .io .buffer .DataBufferFactory ;
32
32
import org .springframework .core .io .buffer .NettyDataBufferFactory ;
33
33
import org .springframework .http .HttpHeaders ;
34
+ import org .springframework .http .HttpStatus ;
34
35
import org .springframework .http .ResponseCookie ;
35
36
import org .springframework .http .ZeroCopyHttpOutputMessage ;
36
37
import org .springframework .util .Assert ;
@@ -60,12 +61,23 @@ public <T> T getNativeResponse() {
60
61
return (T ) this .response ;
61
62
}
62
63
64
+ @ Override
65
+ @ SuppressWarnings ("ConstantConditions" )
66
+ public HttpStatus getStatusCode () {
67
+ HttpStatus httpStatus = super .getStatusCode ();
68
+ if (httpStatus == null ) {
69
+ HttpResponseStatus status = this .response .status ();
70
+ httpStatus = status != null ? HttpStatus .resolve (status .code ()) : null ;
71
+ }
72
+ return httpStatus ;
73
+ }
74
+
63
75
64
76
@ Override
65
77
protected void applyStatusCode () {
66
78
Integer statusCode = getStatusCodeValue ();
67
79
if (statusCode != null ) {
68
- this .response .status (HttpResponseStatus . valueOf ( statusCode ) );
80
+ this .response .status (statusCode );
69
81
}
70
82
}
71
83
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2002-2017 the original author or authors.
2
+ * Copyright 2002-2018 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -34,13 +34,17 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
34
34
/**
35
35
* Set the HTTP status code of the response.
36
36
* @param status the HTTP status as an {@link HttpStatus} enum value
37
- * @return {@code false} if the status code has not been set because the HTTP response
38
- * is already committed, {@code true} if it has been set correctly .
37
+ * @return {@code false} if the status code has not been set because the
38
+ * HTTP response is already committed, {@code true} if successfully set.
39
39
*/
40
40
boolean setStatusCode (@ Nullable HttpStatus status );
41
41
42
42
/**
43
- * Return the HTTP status code or {@code null} if not set.
43
+ * Return the status code set via {@link #setStatusCode}, or if the status
44
+ * has not been set, return the default status code from the underlying
45
+ * server response. The return value may be {@code null} if the status code
46
+ * value is outside the {@link HttpStatus} enum range, or if the underlying
47
+ * server response does not have a default value.
44
48
*/
45
49
@ Nullable
46
50
HttpStatus getStatusCode ();
Original file line number Diff line number Diff line change 34
34
import org .springframework .core .io .buffer .DataBufferFactory ;
35
35
import org .springframework .core .io .buffer .DataBufferUtils ;
36
36
import org .springframework .http .HttpHeaders ;
37
+ import org .springframework .http .HttpStatus ;
37
38
import org .springframework .http .MediaType ;
38
39
import org .springframework .http .ResponseCookie ;
39
40
import org .springframework .lang .Nullable ;
@@ -96,6 +97,12 @@ public <T> T getNativeResponse() {
96
97
return (T ) this .response ;
97
98
}
98
99
100
+ @ Override
101
+ public HttpStatus getStatusCode () {
102
+ HttpStatus httpStatus = super .getStatusCode ();
103
+ return httpStatus != null ? httpStatus : HttpStatus .resolve (this .response .getStatus ());
104
+ }
105
+
99
106
@ Override
100
107
protected void applyStatusCode () {
101
108
Integer statusCode = getStatusCodeValue ();
Original file line number Diff line number Diff line change 35
35
import org .springframework .core .io .buffer .DataBufferFactory ;
36
36
import org .springframework .core .io .buffer .DataBufferUtils ;
37
37
import org .springframework .http .HttpHeaders ;
38
+ import org .springframework .http .HttpStatus ;
38
39
import org .springframework .http .ResponseCookie ;
39
40
import org .springframework .http .ZeroCopyHttpOutputMessage ;
40
41
import org .springframework .lang .Nullable ;
@@ -80,6 +81,12 @@ public <T> T getNativeResponse() {
80
81
return (T ) this .exchange ;
81
82
}
82
83
84
+ @ Override
85
+ public HttpStatus getStatusCode () {
86
+ HttpStatus httpStatus = super .getStatusCode ();
87
+ return httpStatus != null ? httpStatus : HttpStatus .resolve (this .exchange .getStatusCode ());
88
+ }
89
+
83
90
84
91
@ Override
85
92
protected void applyStatusCode () {
You can’t perform that action at this time.
0 commit comments