001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.springframework.web.reactive.socket.client;
017
018import java.net.URI;
019
020import reactor.core.publisher.Mono;
021
022import org.springframework.http.HttpHeaders;
023import org.springframework.web.reactive.socket.WebSocketHandler;
024
025/**
026 * Contract for reactive-style handling of a WebSocket session.
027 *
028 * @author Rossen Stoyanchev
029 * @since 5.0
030 */
031public interface WebSocketClient {
032
033        /**
034         * Execute a handshake request to the given url and handle the resulting
035         * WebSocket session with the given handler.
036         * @param url the handshake url
037         * @param handler the handler of the WebSocket session
038         * @return completion {@code Mono<Void>} to indicate the outcome of the
039         * WebSocket session handling.
040         */
041        Mono<Void> execute(URI url, WebSocketHandler handler);
042
043        /**
044         * A variant of {@link #execute(URI, WebSocketHandler)} with custom headers.
045         * @param url the handshake url
046         * @param headers custom headers for the handshake request
047         * @param handler the handler of the WebSocket session
048         * @return completion {@code Mono<Void>} to indicate the outcome of the
049         * WebSocket session handling.
050         */
051        Mono<Void> execute(URI url, HttpHeaders headers, WebSocketHandler handler);
052
053}