@Override public String toString() { return "HttpClientOptions{" + asDetailedString() + "}"; }
@Override public String toString() { return "HttpClient: " + options.asSimpleString(); }
/** * Return a new {@link InetSocketAddress} from the URI. * <p> * If the port is undefined (-1), a default port is used (80 or 443 depending on * whether the URI is secure or not). If {@link #useProxy(String) a proxy} is used, the * returned address is provided unresolved. * * @param uri {@link URI} to extract host and port information from * @return a new eventual {@link InetSocketAddress} */ public final InetSocketAddress getRemoteAddress(URI uri) { Objects.requireNonNull(uri, "uri"); boolean secure = isSecure(uri); int port = uri.getPort() != -1 ? uri.getPort() : (secure ? 443 : 80); // TODO: find out whether the remote address should be resolved using blocking operation at this point boolean shouldResolveAddress = !useProxy(uri.getHost()); return createInetSocketAddress(uri.getHost(), port, shouldResolveAddress); }
StringBuilder schemeBuilder = new StringBuilder(); if (ws) { schemeBuilder.append(isSecure() ? HttpClient.WSS_SCHEME : HttpClient.WS_SCHEME); schemeBuilder.append(isSecure() ? HttpClient.HTTPS_SCHEME : HttpClient.HTTP_SCHEME); if (url.startsWith("/")) { SocketAddress remote = getAddress();
@Override @SuppressWarnings("unchecked") public Mono<HttpClientResponse> newHandler(BiFunction<? super HttpClientResponse, ? super HttpClientRequest, ? extends Publisher<Void>> ioHandler) { if (Objects.isNull(options.getAddress())) { try { return (Mono<HttpClientResponse>) client.newHandler((BiFunction<NettyInbound, NettyOutbound, Publisher<Void>>) ioHandler, options.getRemoteAddress(new URI("https://localhost")), true, null); } catch (URISyntaxException e) { return Mono.error(e); } } else { return (Mono<HttpClientResponse>) client.newHandler((BiFunction<NettyInbound, NettyOutbound, Publisher<Void>>) ioHandler); } }
@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); }
static Function<? super HttpClientRequest, ? extends Publisher<Void>> handler(Function<? super HttpClientRequest, ? extends Publisher<Void>> h, HttpClientOptions opts) { if (opts.acceptGzip()) { if (h != null) { return req -> h.apply(req.header(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP)); } else { return req -> req.header(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP); } } else { return h; } }
@Override public HttpClientOptions duplicate() { return builder().from(this).build(); }
/** * Get a copy of the {@link HttpClientOptions} currently in effect. * * @return the http client options */ public HttpClientOptions options() { return options.duplicate(); }
@Override public HttpClientOptions build() { super.build(); return new HttpClientOptions(this); } }
MonoHttpClientResponse(HttpClient parent, String url, HttpMethod method, Function<? super HttpClientRequest, ? extends Publisher<Void>> handler) { this.parent = parent; boolean isWs = Objects.equals(method, HttpClient.WS); try { this.startURI = new URI(parent.options.formatSchemeAndHost(url, isWs)); } catch (URISyntaxException e) { throw Exceptions.bubble(e); } this.method = isWs ? HttpMethod.GET : method; this.handler = handler; }
@Override public void accept(ChannelPipeline pipeline, ContextHandler<Channel> c) { pipeline.addLast(NettyPipeline.HttpCodec, new HttpClientCodec()); if (options.acceptGzip()) { pipeline.addAfter(NettyPipeline.HttpCodec, NettyPipeline.HttpDecompressor, new HttpContentDecompressor()); } } }
private HttpClient(HttpClient.Builder builder) { HttpClientOptions.Builder clientOptionsBuilder = HttpClientOptions.builder(); if (Objects.nonNull(builder.options)) { builder.options.accept(clientOptionsBuilder); } if (!clientOptionsBuilder.isLoopAvailable()) { clientOptionsBuilder.loopResources(HttpResources.get()); } if (!clientOptionsBuilder.isPoolAvailable() && !clientOptionsBuilder.isPoolDisabled()) { clientOptionsBuilder.poolResources(HttpResources.get()); } this.options = clientOptionsBuilder.build(); this.client = new TcpBridgeClient(options); }