Example usage for org.springframework.http HttpHeaders getUpgrade

List of usage examples for org.springframework.http HttpHeaders getUpgrade

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders getUpgrade.

Prototype

@Nullable
public String getUpgrade() 

Source Link

Document

Return the value of the Upgrade header.

Usage

From source file:org.springframework.web.reactive.socket.server.support.HandshakeWebSocketService.java

@Override
public Mono<Void> handleRequest(ServerWebExchange exchange, WebSocketHandler handler) {
    ServerHttpRequest request = exchange.getRequest();
    HttpMethod method = request.getMethod();
    HttpHeaders headers = request.getHeaders();

    if (logger.isDebugEnabled()) {
        logger.debug("Handling " + request.getURI() + " with headers: " + headers);
    }/*from w  w w  .j  a  v  a 2s  . c  o  m*/

    if (HttpMethod.GET != method) {
        return Mono.error(
                new MethodNotAllowedException(request.getMethodValue(), Collections.singleton(HttpMethod.GET)));
    }

    if (!"WebSocket".equalsIgnoreCase(headers.getUpgrade())) {
        return handleBadRequest("Invalid 'Upgrade' header: " + headers);
    }

    List<String> connectionValue = headers.getConnection();
    if (!connectionValue.contains("Upgrade") && !connectionValue.contains("upgrade")) {
        return handleBadRequest("Invalid 'Connection' header: " + headers);
    }

    String key = headers.getFirst(SEC_WEBSOCKET_KEY);
    if (key == null) {
        return handleBadRequest("Missing \"Sec-WebSocket-Key\" header");
    }

    String protocol = selectProtocol(headers, handler);
    return this.upgradeStrategy.upgrade(exchange, handler, protocol);
}