/** * Creates a simple HTTP client using provided {@link HttpClientOptions options} * * @param options the options for the client, including the address to which this * client should connect * @return a simple HTTP client using provided {@link HttpClientOptions options} */ public static HttpClient create(Consumer<? super HttpClientOptions.Builder> options) { return builder().options(options).build(); }
/** * Creates a simple HTTP client bound on the provided address and port * * @param address the host to which this client should connect. * @param port the port to which this client should connect. * @return a simple HTTP client bound on the provided address and port */ public static HttpClient create(String address, int port) { return create(opts -> opts.host(address).port(port)); }
@Override @SuppressWarnings("unchecked") public void subscribe(final CoreSubscriber<? super HttpClientResponse> subscriber) { ReconnectableBridge bridge = new ReconnectableBridge(); bridge.activeURI = startURI; Mono.defer(() -> parent.client.newHandler(new HttpClientHandler(this, bridge), parent.options.getRemoteAddress(bridge.activeURI), HttpClientOptions.isSecure(bridge.activeURI), bridge)) .retry(bridge) .cast(HttpClientResponse.class) .subscribe(subscriber); }
/** * Creates a simple HTTP Client with no address to which this client should connect * and with default sslContext support. * * @return a simple HTTP client */ public static HttpClient create() { return create(HttpClientOptions.Builder::sslSupport); }
/** * Duplex conversion to {@link WebsocketInbound}, {@link WebsocketOutbound} and a * closing {@link Publisher}. Mono and Callback are invoked on handshake success, * otherwise the returned {@link Mono} fails. * * @param websocketHandler the in/out handler for ws transport * * @return a {@link Mono} completing when upgrade is confirmed */ default Mono<Void> receiveWebsocket(BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler) { return receiveWebsocket(null, websocketHandler); }
/** * HTTP DELETE the passed URL. * * @param url the target remote URL * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> delete(String url) { return request(HttpMethod.DELETE, url, null); }
@Override public HttpClientRequest.Form files(String name, File[] files, String[] contentTypes) { for (int i = 0; i < files.length; i++) { file(name, files[i], contentTypes[i]); } return this; }
static HttpClientOperations bindHttp(Channel channel, BiFunction<? super HttpClientResponse, ? super HttpClientRequest, ? extends Publisher<Void>> handler, ContextHandler<?> context) { return new HttpClientOperations(channel, handler, context); }
@Override public HttpClientRequest.Form multipart(boolean isMultipart) { this.needNewEncoder = isChunked() != isMultipart; this.newMultipart = isMultipart; return this; }
/** * Create a new HttpClientOptions.Builder * * @return a new HttpClientOptions.Builder */ @SuppressWarnings("unchecked") public static HttpClientOptions.Builder builder() { return new HttpClientOptions.Builder(); }
@Override public HttpClientRequest.Form textFile(String name, InputStream stream) { textFile(name, stream, null); return this; }
/** * Creates a builder for {@link HttpClient HttpClient} * * @return a new HttpClient builder */ public static HttpClient.Builder builder() { return new HttpClient.Builder(); }
/** * Get a copy of the {@link HttpClientOptions} currently in effect. * * @return the http client options */ public HttpClientOptions options() { return options.duplicate(); }
/** * Constructor that accepts an {@link HttpClientOptions} consumer to supply * to {@link HttpClient#create(Consumer)}. */ public ReactorNettyWebSocketClient(Consumer<? super HttpClientOptions> clientOptions) { this.httpClient = HttpClient.create(clientOptions); }
/** * HTTP PATCH the passed URL. * * @param url the target remote URL * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> patch(String url) { return request(HttpMethod.PATCH, url, null); }
@Override public HttpClientRequest.Form file(String name, InputStream inputStream) { file(name, inputStream, null); return this; }
/** * Creates a simple HTTP client bound on localhost and the provided port * * @param port the port to which this client should connect. * @return a simple HTTP client bound on localhost and the provided port */ public static HttpClient create(int port) { return create("localhost", port); }
/** * HTTP GET the passed URL. When connection has been made, the passed handler is * invoked and can be used to tune the request and write data to it. * * @param url the target remote URL * @param handler the {@link Function} to invoke on open channel * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> get(String url, Function<? super HttpClientRequest, ? extends Publisher<Void>> handler) { return request(HttpMethod.GET, url, handler); }
/** * HTTP GET the passed URL. * * @param url the target remote URL * @return a {@link Mono} of the {@link HttpServerResponse} ready to consume for * response */ public final Mono<HttpClientResponse> get(String url) { return request(HttpMethod.GET, url, null); }