io.vertx.rxjava3.core.http.HttpClientBuilder Maven / Gradle / Ivy
/*
* Copyright 2014 Red Hat, Inc.
*
* Red Hat licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package io.vertx.rxjava3.core.http;
import io.vertx.rxjava3.RxHelper;
import io.vertx.rxjava3.ObservableHelper;
import io.vertx.rxjava3.FlowableHelper;
import io.vertx.rxjava3.impl.AsyncResultMaybe;
import io.vertx.rxjava3.impl.AsyncResultSingle;
import io.vertx.rxjava3.impl.AsyncResultCompletable;
import io.vertx.rxjava3.WriteStreamObserver;
import io.vertx.rxjava3.WriteStreamSubscriber;
import java.util.Map;
import java.util.Set;
import java.util.List;
import java.util.Iterator;
import java.util.function.Function;
import java.util.stream.Collectors;
import io.vertx.core.Handler;
import io.vertx.core.AsyncResult;
import io.vertx.core.json.JsonObject;
import io.vertx.core.json.JsonArray;
import io.vertx.lang.rx.RxGen;
import io.vertx.lang.rx.TypeArg;
import io.vertx.lang.rx.MappingIterator;
/**
* A builder for {@link io.vertx.rxjava3.core.http.HttpClient}.
*
*
* NOTE: This class has been automatically generated from the {@link io.vertx.core.http.HttpClientBuilder original} non RX-ified interface using Vert.x codegen.
*/
@RxGen(io.vertx.core.http.HttpClientBuilder.class)
public class HttpClientBuilder {
@Override
public String toString() {
return delegate.toString();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
HttpClientBuilder that = (HttpClientBuilder) o;
return delegate.equals(that.delegate);
}
@Override
public int hashCode() {
return delegate.hashCode();
}
public static final TypeArg __TYPE_ARG = new TypeArg<>( obj -> new HttpClientBuilder((io.vertx.core.http.HttpClientBuilder) obj),
HttpClientBuilder::getDelegate
);
private final io.vertx.core.http.HttpClientBuilder delegate;
public HttpClientBuilder(io.vertx.core.http.HttpClientBuilder delegate) {
this.delegate = delegate;
}
public HttpClientBuilder(Object delegate) {
this.delegate = (io.vertx.core.http.HttpClientBuilder)delegate;
}
public io.vertx.core.http.HttpClientBuilder getDelegate() {
return delegate;
}
/**
* Configure the client options.
* @param options the client options
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava3.core.http.HttpClientBuilder with(io.vertx.core.http.HttpClientOptions options) {
delegate.with(options);
return this;
}
/**
* Configure the client with the given pool options
.
* @param options the pool options
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava3.core.http.HttpClientBuilder with(io.vertx.core.http.PoolOptions options) {
delegate.with(options);
return this;
}
/**
* Set a connection handler for the client. This handler is called when a new connection is established.
* @param handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava3.core.http.HttpClientBuilder withConnectHandler(io.vertx.core.Handler handler) {
delegate.withConnectHandler(new io.vertx.lang.rx.DelegatingHandler<>(handler, event -> io.vertx.rxjava3.core.http.HttpConnection.newInstance((io.vertx.core.http.HttpConnection)event)));
return this;
}
/**
* Set a redirect handler for the http client.
*
* The redirect handler is called when a 3xx
response is received and the request is configured to
* follow redirects with {@link io.vertx.rxjava3.core.http.HttpClientRequest#setFollowRedirects}.
*
* The redirect handler is passed the {@link io.vertx.rxjava3.core.http.HttpClientResponse}, it can return an {@link io.vertx.rxjava3.core.http.HttpClientRequest} or null
.
*
* - when null is returned, the original response is processed by the original request response handler
* - when a new
Future
is returned, the client will send this new request
*
* The new request will get a copy of the previous request headers unless headers are set. In this case,
* the client assumes that the redirect handler exclusively managers the headers of the new request.
*
* The handler must return a Future
unsent so the client can further configure it and send it.
* @param handler the new redirect handler
* @return a reference to this, so the API can be used fluently
*/
public io.vertx.rxjava3.core.http.HttpClientBuilder withRedirectHandler(java.util.function.Function> handler) {
delegate.withRedirectHandler(new Function>() {
public io.vertx.core.Future apply(io.vertx.core.http.HttpClientResponse arg) {
io.reactivex.rxjava3.core.Single ret = handler.apply(io.vertx.rxjava3.core.http.HttpClientResponse.newInstance((io.vertx.core.http.HttpClientResponse)arg));
return io.vertx.rxjava3.SingleHelper.toFuture(ret, obj -> obj);
}
});
return this;
}
/**
* Build and return the client.
* @return the client as configured by this builder
*/
public io.vertx.rxjava3.core.http.HttpClient build() {
io.vertx.rxjava3.core.http.HttpClient ret = io.vertx.rxjava3.core.http.HttpClient.newInstance((io.vertx.core.http.HttpClient)delegate.build());
return ret;
}
public static HttpClientBuilder newInstance(io.vertx.core.http.HttpClientBuilder arg) {
return arg != null ? new HttpClientBuilder(arg) : null;
}
}