
io.reactivex.netty.protocol.http.client.internal.HttpClientRequestImpl Maven / Gradle / Ivy
/*
* Copyright 2016 Netflix, Inc.
*
* Licensed 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.reactivex.netty.protocol.http.client.internal;
import io.netty.handler.codec.http.HttpMethod;
import io.netty.handler.codec.http.HttpVersion;
import io.netty.handler.codec.http.cookie.Cookie;
import io.reactivex.netty.channel.AllocatingTransformer;
import io.reactivex.netty.channel.AppendTransformerEvent;
import io.reactivex.netty.channel.Connection;
import io.reactivex.netty.events.Clock;
import io.reactivex.netty.events.EventAttributeKeys;
import io.reactivex.netty.events.EventPublisher;
import io.reactivex.netty.internal.VoidToAnythingCast;
import io.reactivex.netty.protocol.http.TrailingHeaders;
import io.reactivex.netty.protocol.http.client.HttpClientRequest;
import io.reactivex.netty.protocol.http.client.HttpClientResponse;
import io.reactivex.netty.protocol.http.client.events.HttpClientEventsListener;
import io.reactivex.netty.protocol.http.internal.OperatorTrailer;
import io.reactivex.netty.protocol.http.ws.client.internal.WebSocketRequestImpl;
import io.reactivex.netty.protocol.tcp.client.TcpClient;
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func0;
import rx.functions.Func1;
import rx.functions.Func2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static java.util.concurrent.TimeUnit.*;
public final class HttpClientRequestImpl extends HttpClientRequest {
public static final int NO_REDIRECTS = -1;
private final List immutableTransformers;
private final List immutableResponseTransformers;
private final RawRequest rawRequest;
private final TcpClient, HttpClientResponse> client;
private final Func1 flushOnEachSelector = new Func1() {
@Override
public Boolean call(I next) {
return true;
}
};
private HttpClientRequestImpl(final RawRequest rawRequest, final TcpClient, HttpClientResponse> client,
List immutableTransformers,
List immutableResponseTransformers) {
super(new OnSubscribeFuncImpl<>(client, rawRequest, immutableResponseTransformers, immutableTransformers));
this.rawRequest = rawRequest;
this.client = client;
this.immutableTransformers = immutableTransformers;
this.immutableResponseTransformers = immutableResponseTransformers;
}
@Override
public Observable> writeContent(Observable contentSource) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, false);
}
@Override
public Observable> writeContentAndFlushOnEach(Observable contentSource) {
return writeContent(contentSource, flushOnEachSelector);
}
@Override
public Observable> writeStringContent(Observable contentSource) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, false);
}
@Override
public Observable> writeBytesContent(Observable contentSource) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, false);
}
@Override
public Observable> writeContent(Observable contentSource,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, flushSelector, false);
}
@Override
public Observable> writeStringContent(Observable contentSource,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, flushSelector, false);
}
@Override
public Observable> writeBytesContent(Observable contentSource,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(rawObservable, flushSelector, false);
}
@Override
public Observable> writeContent(Observable contentSource,
final Func0 trailerFactory,
final Func2 trailerMutator) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), true);
}
@Override
public Observable> writeStringContent(Observable contentSource,
Func0 trailerFactory,
Func2 trailerMutator) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), true);
}
@Override
public Observable> writeBytesContent(Observable contentSource,
Func0 trailerFactory,
Func2 trailerMutator) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), true);
}
@Override
public Observable> writeContent(Observable contentSource,
Func0 trailerFactory,
Func2 trailerMutator,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), flushSelector,
true);
}
@Override
public Observable> writeStringContent(
Observable contentSource, Func0 trailerFactory, Func2 trailerMutator,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), flushSelector,
true);
}
@Override
public Observable> writeBytesContent(
Observable contentSource, Func0 trailerFactory, Func2 trailerMutator,
Func1 flushSelector) {
@SuppressWarnings("rawtypes")
Observable rawObservable = contentSource;
return _writeContentRaw(OperatorTrailer.liftFrom(rawObservable, trailerFactory, trailerMutator), flushSelector,
true);
}
@Override
public HttpClientRequestImpl readTimeOut(int timeOut, TimeUnit timeUnit) {
return _copy(client.readTimeOut(timeOut, timeUnit));
}
@Override
public HttpClientRequestImpl followRedirects(int maxRedirects) {
final Redirector redirector = new Redirector<>(maxRedirects, client);
HttpClientRequestImpl toReturn = _copy(client, rawRequest.followRedirect(redirector));
redirector.setOriginalRequest(toReturn.rawRequest);
return toReturn;
}
@Override
public HttpClientRequestImpl followRedirects(boolean follow) {
return follow ? followRedirects(Redirector.DEFAULT_MAX_REDIRECTS) : followRedirects(NO_REDIRECTS);
}
@Override
public HttpClientRequestImpl setMethod(HttpMethod method) {
return _copy(client, rawRequest.setMethod(method));
}
@Override
public HttpClientRequestImpl setUri(String newUri) {
return _copy(client, rawRequest.setUri(newUri));
}
@Override
public HttpClientRequestImpl addHeader(CharSequence name, Object value) {
return _copy(client, rawRequest.addHeader(name, value));
}
@Override
public HttpClientRequest addHeaders(Map extends CharSequence, ? extends Iterable
© 2015 - 2025 Weber Informatics LLC | Privacy Policy