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
32843284 return this ;
32853285 }
32863286
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+
32873301 /**
32883302 * Configures the Strict Transport Security response headers
32893303 * @return the {@link HstsSpec} to configure
Original file line number Diff line number Diff line change 2424
2525import org .junit .Before ;
2626import org .junit .Test ;
27+ import reactor .core .publisher .Mono ;
2728
2829import org .springframework .http .HttpHeaders ;
2930import org .springframework .security .test .web .reactive .server .WebTestClientBuilder ;
4647 *
4748 * @author Rob Winch
4849 * @author Vedran Pavic
50+ * @author Ankur Pathak
4951 * @since 5.0
5052 */
5153public class HeaderSpecTests {
54+ private final static String CUSTOM_HEADER = "CUSTOM-HEADER" ;
55+ private final static String CUSTOM_VALUE = "CUSTOM-VALUE" ;
5256
5357 private ServerHttpSecurity http = ServerHttpSecurity .http ();
5458
@@ -387,6 +391,20 @@ public void headersWhenReferrerPolicyCustomEnabledInLambdaThenCustomReferrerPoli
387391 assertHeaders ();
388392 }
389393
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+
390408 private void expectHeaderNamesNotPresent (String ... headerNames ) {
391409 for (String headerName : headerNames ) {
392410 this .expectedHeaders .remove (headerName );
You can’t perform that action at this time.
0 commit comments