001/* 002 * Copyright 2002-2018 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 */ 016 017package org.springframework.http.client.reactive; 018 019import java.net.URI; 020import java.util.function.Function; 021 022import reactor.core.publisher.Mono; 023 024import org.springframework.http.HttpMethod; 025 026/** 027 * Abstraction over HTTP clients driving the underlying HTTP client to connect 028 * to the origin server and provide all necessary infrastructure to send a 029 * {@link ClientHttpRequest} and receive a {@link ClientHttpResponse}. 030 * 031 * @author Brian Clozel 032 * @since 5.0 033 */ 034public interface ClientHttpConnector { 035 036 /** 037 * Connect to the origin server using the given {@code HttpMethod} and 038 * {@code URI} and apply the given {@code requestCallback} when the HTTP 039 * request of the underlying API can be initialized and written to. 040 * @param method the HTTP request method 041 * @param uri the HTTP request URI 042 * @param requestCallback a function that prepares and writes to the request, 043 * returning a publisher that signals when it's done writing. 044 * Implementations can return a {@code Mono<Void>} by calling 045 * {@link ClientHttpRequest#writeWith} or {@link ClientHttpRequest#setComplete}. 046 * @return publisher for the {@link ClientHttpResponse} 047 */ 048 Mono<ClientHttpResponse> connect(HttpMethod method, URI uri, 049 Function<? super ClientHttpRequest, Mono<Void>> requestCallback); 050 051}