File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
main/java/org/springframework/security/config/web/server
test/java/org/springframework/security/config/web/server Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -3284,6 +3284,20 @@ public HeaderSpec frameOptions(Customizer<FrameOptionsSpec> frameOptionsCustomiz
3284
3284
return this ;
3285
3285
}
3286
3286
3287
+ /**
3288
+ * Configures custom headers writer
3289
+ *
3290
+ * @param serverHttpHeadersWriter the {@link ServerHttpHeadersWriter} to provide custom headers writer
3291
+ * @return the {@link HeaderSpec} to customize
3292
+ * @since 5.3.0
3293
+ * @author Ankur Pathak
3294
+ */
3295
+ public HeaderSpec writer (ServerHttpHeadersWriter serverHttpHeadersWriter ) {
3296
+ Assert .notNull (serverHttpHeadersWriter , () -> "serverHttpHeadersWriter cannot be null" );
3297
+ this .writers .add (serverHttpHeadersWriter );
3298
+ return this ;
3299
+ }
3300
+
3287
3301
/**
3288
3302
* Configures the Strict Transport Security response headers
3289
3303
* @return the {@link HstsSpec} to configure
Original file line number Diff line number Diff line change 24
24
25
25
import org .junit .Before ;
26
26
import org .junit .Test ;
27
+ import reactor .core .publisher .Mono ;
27
28
28
29
import org .springframework .http .HttpHeaders ;
29
30
import org .springframework .security .test .web .reactive .server .WebTestClientBuilder ;
46
47
*
47
48
* @author Rob Winch
48
49
* @author Vedran Pavic
50
+ * @author Ankur Pathak
49
51
* @since 5.0
50
52
*/
51
53
public class HeaderSpecTests {
54
+ private final static String CUSTOM_HEADER = "CUSTOM-HEADER" ;
55
+ private final static String CUSTOM_VALUE = "CUSTOM-VALUE" ;
52
56
53
57
private ServerHttpSecurity http = ServerHttpSecurity .http ();
54
58
@@ -387,6 +391,20 @@ public void headersWhenReferrerPolicyCustomEnabledInLambdaThenCustomReferrerPoli
387
391
assertHeaders ();
388
392
}
389
393
394
+ @ Test
395
+ public void headersWhenCustomHeadersWriter () {
396
+ this .expectedHeaders .add (CUSTOM_HEADER , CUSTOM_VALUE );
397
+ this .http .headers (headers -> headers .writer (exchange -> {
398
+ return Mono .just (exchange )
399
+ .doOnNext (it -> {
400
+ it .getResponse ().getHeaders ().add (CUSTOM_HEADER , CUSTOM_VALUE );
401
+ }).then ();
402
+
403
+ }));
404
+
405
+ assertHeaders ();
406
+ }
407
+
390
408
private void expectHeaderNamesNotPresent (String ... headerNames ) {
391
409
for (String headerName : headerNames ) {
392
410
this .expectedHeaders .remove (headerName );
You can’t perform that action at this time.
0 commit comments