org.springframework.web.reactive.function.server.ServerResponse设置响应头

  • 记录一下
        String host = serverRequest.uri().getHost();
        Consumer<HttpHeaders> headersConsumer = consumer -> {
            consumer.setAccessControlAllowOrigin(host);
            consumer.setAccessControlAllowCredentials(true);
            consumer.set("Access-Control-Allow-Headers","*");
            consumer.set("Access-Control-Allow-Methods", "*");
            consumer.setAccessControlMaxAge(3600);
        };
		ServerResponse.status(HttpStatus.OK).headers(headersConsumer).body(BodyInserters.fromValue(result));

函数式路由匹配,进行响应头的设置。

你可能感兴趣的:(java,spring)