File tree 6 files changed +18
-57
lines changed
spring-web/src/main/java/org/springframework/http
spring-webflux/src/main/java/org/springframework/web/reactive/function/server
spring-webmvc/src/main/java/org/springframework/web/servlet/function
6 files changed +18
-57
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,15 @@ public static List<ETag> parse(String source) {
134
134
return result ;
135
135
}
136
136
137
+ public static String format (String etag ) {
138
+ if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
139
+ etag = "\" " + etag ;
140
+ }
141
+ if (!etag .endsWith ("\" " )) {
142
+ etag = etag + "\" " ;
143
+ }
144
+ return etag ;
145
+ }
137
146
138
147
private enum State {
139
148
Original file line number Diff line number Diff line change @@ -570,12 +570,7 @@ public BodyBuilder contentType(MediaType contentType) {
570
570
@ Override
571
571
public BodyBuilder eTag (@ Nullable String etag ) {
572
572
if (etag != null ) {
573
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
574
- etag = "\" " + etag ;
575
- }
576
- if (!etag .endsWith ("\" " )) {
577
- etag = etag + "\" " ;
578
- }
573
+ etag = ETag .format (etag );
579
574
}
580
575
this .headers .setETag (etag );
581
576
return this ;
Original file line number Diff line number Diff line change 28
28
import java .util .Set ;
29
29
import java .util .function .Consumer ;
30
30
31
+ import org .springframework .http .*;
31
32
import reactor .core .publisher .Mono ;
32
33
33
34
import org .springframework .core .codec .Hints ;
34
- import org .springframework .http .CacheControl ;
35
- import org .springframework .http .HttpHeaders ;
36
- import org .springframework .http .HttpMethod ;
37
- import org .springframework .http .HttpStatus ;
38
- import org .springframework .http .HttpStatusCode ;
39
- import org .springframework .http .MediaType ;
40
- import org .springframework .http .ResponseCookie ;
41
35
import org .springframework .http .codec .HttpMessageWriter ;
42
36
import org .springframework .http .server .reactive .ServerHttpRequest ;
43
37
import org .springframework .http .server .reactive .ServerHttpResponse ;
@@ -148,12 +142,7 @@ public EntityResponse.Builder<T> contentType(MediaType contentType) {
148
142
149
143
@ Override
150
144
public EntityResponse .Builder <T > eTag (String etag ) {
151
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
152
- etag = "\" " + etag ;
153
- }
154
- if (!etag .endsWith ("\" " )) {
155
- etag = etag + "\" " ;
156
- }
145
+ etag = ETag .format (etag );
157
146
this .headers .setETag (etag );
158
147
return this ;
159
148
}
Original file line number Diff line number Diff line change 32
32
import java .util .function .Function ;
33
33
34
34
import org .reactivestreams .Publisher ;
35
+ import org .springframework .http .*;
35
36
import reactor .core .publisher .Mono ;
36
37
37
38
import org .springframework .core .ParameterizedTypeReference ;
38
39
import org .springframework .core .codec .Hints ;
39
- import org .springframework .http .CacheControl ;
40
- import org .springframework .http .HttpHeaders ;
41
- import org .springframework .http .HttpMethod ;
42
- import org .springframework .http .HttpStatusCode ;
43
- import org .springframework .http .MediaType ;
44
- import org .springframework .http .ReactiveHttpOutputMessage ;
45
- import org .springframework .http .ResponseCookie ;
46
40
import org .springframework .http .codec .HttpMessageWriter ;
47
41
import org .springframework .http .server .reactive .ServerHttpRequest ;
48
42
import org .springframework .http .server .reactive .ServerHttpResponse ;
@@ -148,12 +142,7 @@ public ServerResponse.BodyBuilder contentType(MediaType contentType) {
148
142
@ Override
149
143
public ServerResponse .BodyBuilder eTag (String etag ) {
150
144
Assert .notNull (etag , "etag must not be null" );
151
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
152
- etag = "\" " + etag ;
153
- }
154
- if (!etag .endsWith ("\" " )) {
155
- etag = etag + "\" " ;
156
- }
145
+ etag = ETag .format (etag );
157
146
this .headers .setETag (etag );
158
147
return this ;
159
148
}
Original file line number Diff line number Diff line change 45
45
import org .springframework .core .io .InputStreamResource ;
46
46
import org .springframework .core .io .Resource ;
47
47
import org .springframework .core .io .support .ResourceRegion ;
48
- import org .springframework .http .CacheControl ;
49
- import org .springframework .http .HttpHeaders ;
50
- import org .springframework .http .HttpMethod ;
51
- import org .springframework .http .HttpRange ;
52
- import org .springframework .http .HttpStatus ;
53
- import org .springframework .http .HttpStatusCode ;
54
- import org .springframework .http .InvalidMediaTypeException ;
55
- import org .springframework .http .MediaType ;
48
+ import org .springframework .http .*;
56
49
import org .springframework .http .converter .GenericHttpMessageConverter ;
57
50
import org .springframework .http .converter .HttpMessageConverter ;
58
51
import org .springframework .http .converter .SmartHttpMessageConverter ;
@@ -166,12 +159,7 @@ public EntityResponse.Builder<T> contentType(MediaType contentType) {
166
159
167
160
@ Override
168
161
public EntityResponse .Builder <T > eTag (String etag ) {
169
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
170
- etag = "\" " + etag ;
171
- }
172
- if (!etag .endsWith ("\" " )) {
173
- etag = etag + "\" " ;
174
- }
162
+ etag = ETag .format (etag );
175
163
this .headers .setETag (etag );
176
164
return this ;
177
165
}
Original file line number Diff line number Diff line change 30
30
import jakarta .servlet .http .HttpServletResponse ;
31
31
32
32
import org .springframework .core .ParameterizedTypeReference ;
33
- import org .springframework .http .CacheControl ;
34
- import org .springframework .http .HttpHeaders ;
35
- import org .springframework .http .HttpMethod ;
36
- import org .springframework .http .HttpStatusCode ;
37
- import org .springframework .http .MediaType ;
33
+ import org .springframework .http .*;
38
34
import org .springframework .lang .Nullable ;
39
35
import org .springframework .util .Assert ;
40
36
import org .springframework .util .LinkedMultiValueMap ;
@@ -128,12 +124,7 @@ public ServerResponse.BodyBuilder contentType(MediaType contentType) {
128
124
@ Override
129
125
public ServerResponse .BodyBuilder eTag (String etag ) {
130
126
Assert .notNull (etag , "etag must not be null" );
131
- if (!etag .startsWith ("\" " ) && !etag .startsWith ("W/\" " )) {
132
- etag = "\" " + etag ;
133
- }
134
- if (!etag .endsWith ("\" " )) {
135
- etag = etag + "\" " ;
136
- }
127
+ etag = ETag .format (etag );
137
128
this .headers .setETag (etag );
138
129
return this ;
139
130
}
You can’t perform that action at this time.
0 commit comments