Polish WebSocket-related
This commit is contained in:
parent
c30145d6f9
commit
e818b904ad
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2015 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -16,20 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.web.cors.reactive;
|
package org.springframework.web.cors.reactive;
|
||||||
|
|
||||||
import reactor.core.publisher.Mono;
|
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.web.cors.CorsConfiguration;
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
import org.springframework.web.server.ServerWebExchange;
|
import org.springframework.web.server.ServerWebExchange;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A strategy that takes a reactive HTTP exchange and a {@link CorsConfiguration} and
|
* A strategy to apply CORS validation checks and updates to a
|
||||||
* updates the response.
|
* {@link ServerWebExchange}, either rejecting through the response or adding
|
||||||
*
|
* CORS related headers, based on a pre-selected {@link CorsConfiguration}.
|
||||||
* <p>This component is not concerned with how a {@code CorsConfiguration} is
|
|
||||||
* selected but rather takes follow-up actions such as applying CORS validation
|
|
||||||
* checks and either rejecting the response or adding CORS headers to the
|
|
||||||
* response.
|
|
||||||
*
|
*
|
||||||
* @author Sebastien Deleuze
|
* @author Sebastien Deleuze
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
|
|
@ -39,10 +33,11 @@ import org.springframework.web.server.ServerWebExchange;
|
||||||
public interface CorsProcessor {
|
public interface CorsProcessor {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process an HTTP exchange given a {@code CorsConfiguration}.
|
* Process a request using the given {@code CorsConfiguration}.
|
||||||
* @param configuration the applicable CORS configuration (possibly {@code null})
|
* @param configuration the CORS configuration to use; possibly {@code null}
|
||||||
* @param exchange the current HTTP request / response
|
* in which case pre-flight requests are rejected, but all others allowed.
|
||||||
* @return a {@link Mono} emitting {@code false} if the request is rejected, {@code true} otherwise
|
* @param exchange the current exchange
|
||||||
|
* @return {@code false} if the request was rejected, {@code true} otherwise
|
||||||
*/
|
*/
|
||||||
boolean process(@Nullable CorsConfiguration configuration, ServerWebExchange exchange);
|
boolean process(@Nullable CorsConfiguration configuration, ServerWebExchange exchange);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import org.springframework.web.reactive.socket.HandshakeInfo;
|
||||||
import org.springframework.web.reactive.socket.adapter.StandardWebSocketSession;
|
import org.springframework.web.reactive.socket.adapter.StandardWebSocketSession;
|
||||||
import org.springframework.web.reactive.socket.adapter.TomcatWebSocketSession;
|
import org.springframework.web.reactive.socket.adapter.TomcatWebSocketSession;
|
||||||
|
|
||||||
|
import org.apache.tomcat.websocket.WsWebSocketContainer;
|
||||||
import reactor.core.publisher.MonoProcessor;
|
import reactor.core.publisher.MonoProcessor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -35,6 +36,7 @@ public class TomcatWebSocketClient extends StandardWebSocketClient {
|
||||||
|
|
||||||
|
|
||||||
public TomcatWebSocketClient() {
|
public TomcatWebSocketClient() {
|
||||||
|
this(new WsWebSocketContainer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public TomcatWebSocketClient(WebSocketContainer webSocketContainer) {
|
public TomcatWebSocketClient(WebSocketContainer webSocketContainer) {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ public interface RequestUpgradeStrategy {
|
||||||
* @return completion {@code Mono<Void>} to indicate the outcome of the
|
* @return completion {@code Mono<Void>} to indicate the outcome of the
|
||||||
* WebSocket session handling.
|
* WebSocket session handling.
|
||||||
*/
|
*/
|
||||||
Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler, @Nullable String subProtocol);
|
Mono<Void> upgrade(ServerWebExchange exchange, WebSocketHandler webSocketHandler,
|
||||||
|
@Nullable String subProtocol);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ public abstract class AbstractWebSocketIntegrationTests {
|
||||||
public static Object[][] arguments() throws IOException {
|
public static Object[][] arguments() throws IOException {
|
||||||
|
|
||||||
WebSocketClient[] clients = new WebSocketClient[] {
|
WebSocketClient[] clients = new WebSocketClient[] {
|
||||||
new TomcatWebSocketClient(new WsWebSocketContainer()),
|
new TomcatWebSocketClient(),
|
||||||
new JettyWebSocketClient(),
|
new JettyWebSocketClient(),
|
||||||
new ReactorNettyWebSocketClient(),
|
new ReactorNettyWebSocketClient(),
|
||||||
new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY))
|
new UndertowWebSocketClient(Xnio.getInstance().createWorker(OptionMap.EMPTY))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue