CARVIEW |
Select Language
HTTP/2 200
date: Wed, 23 Jul 2025 16:29:24 GMT
content-type: text/html; charset=utf-8
cache-control: max-age=0, private, must-revalidate
content-security-policy: default-src 'none'; base-uri 'self'; child-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/; connect-src 'self' uploads.github.com www.githubstatus.com collector.github.com raw.githubusercontent.com api.github.com github-cloud.s3.amazonaws.com github-production-repository-file-5c1aeb.s3.amazonaws.com github-production-upload-manifest-file-7fdce7.s3.amazonaws.com github-production-user-asset-6210df.s3.amazonaws.com *.rel.tunnels.api.visualstudio.com wss://*.rel.tunnels.api.visualstudio.com objects-origin.githubusercontent.com copilot-proxy.githubusercontent.com proxy.individual.githubcopilot.com proxy.business.githubcopilot.com proxy.enterprise.githubcopilot.com *.actions.githubusercontent.com wss://*.actions.githubusercontent.com productionresultssa0.blob.core.windows.net/ productionresultssa1.blob.core.windows.net/ productionresultssa2.blob.core.windows.net/ productionresultssa3.blob.core.windows.net/ productionresultssa4.blob.core.windows.net/ productionresultssa5.blob.core.windows.net/ productionresultssa6.blob.core.windows.net/ productionresultssa7.blob.core.windows.net/ productionresultssa8.blob.core.windows.net/ productionresultssa9.blob.core.windows.net/ productionresultssa10.blob.core.windows.net/ productionresultssa11.blob.core.windows.net/ productionresultssa12.blob.core.windows.net/ productionresultssa13.blob.core.windows.net/ productionresultssa14.blob.core.windows.net/ productionresultssa15.blob.core.windows.net/ productionresultssa16.blob.core.windows.net/ productionresultssa17.blob.core.windows.net/ productionresultssa18.blob.core.windows.net/ productionresultssa19.blob.core.windows.net/ github-production-repository-image-32fea6.s3.amazonaws.com github-production-release-asset-2e65be.s3.amazonaws.com insights.github.com wss://alive.github.com api.githubcopilot.com api.individual.githubcopilot.com api.business.githubcopilot.com api.enterprise.githubcopilot.com; font-src github.githubassets.com; form-action 'self' github.com gist.github.com copilot-workspace.githubnext.com objects-origin.githubusercontent.com; frame-ancestors 'none'; frame-src viewscreen.githubusercontent.com notebooks.githubusercontent.com; img-src 'self' data: blob: github.githubassets.com media.githubusercontent.com camo.githubusercontent.com identicons.github.com avatars.githubusercontent.com private-avatars.githubusercontent.com github-cloud.s3.amazonaws.com objects.githubusercontent.com release-assets.githubusercontent.com secured-user-images.githubusercontent.com/ user-images.githubusercontent.com/ private-user-images.githubusercontent.com opengraph.githubassets.com copilotprodattachments.blob.core.windows.net/github-production-copilot-attachments/ github-production-user-asset-6210df.s3.amazonaws.com customer-stories-feed.github.com spotlights-feed.github.com objects-origin.githubusercontent.com *.githubusercontent.com; manifest-src 'self'; media-src github.com user-images.githubusercontent.com/ secured-user-images.githubusercontent.com/ private-user-images.githubusercontent.com github-production-user-asset-6210df.s3.amazonaws.com gist.github.com; script-src github.githubassets.com; style-src 'unsafe-inline' github.githubassets.com; upgrade-insecure-requests; worker-src github.githubassets.com github.com/assets-cdn/worker/ github.com/assets/ gist.github.com/assets-cdn/worker/
link: ; rel=preload; as=fetch; crossorigin=use-credentials
referrer-policy: no-referrer-when-downgrade
server-timing: issue_layout-fragment;desc="issue_layout fragment";dur=301.215759,issue_conversation_content-fragment;desc="issue_conversation_content fragment";dur=779.687627,issue_conversation_sidebar-fragment;desc="issue_conversation_sidebar fragment";dur=55.892375,nginx;desc="NGINX";dur=1.447813,glb;desc="GLB";dur=101.266706
strict-transport-security: max-age=31536000; includeSubdomains; preload
vary: X-PJAX, X-PJAX-Container, Turbo-Visit, Turbo-Frame, X-Requested-With, Accept,Accept-Encoding, Accept, X-Requested-With
x-content-type-options: nosniff
x-frame-options: deny
x-voltron-version: fd8fbbc
x-xss-protection: 0
server: github.com
content-encoding: gzip
accept-ranges: bytes
set-cookie: _gh_sess=WDcBo7xUtuEkxf5lePnBkiroS25MyHJ33qYUdGTEHhUs4dtNwZokhGpMtD1Uj4orInGcwu3vH%2BYY4l6OP5aeWlCcmyVcDnQPZr1D4QtcoVrP%2BpH5x4%2FgfTx3sgr9zQZ4xSf130SSVX2c%2B1HnC9O4rUwRSxVpn0wTr4aoaahPCZZf8CaIsehFJcH7IBmObFnC7nZUz%2Fe1DdkkLU9R%2FXJp6UpAWYpr32FVmzO%2F%2BBEVKktVkW%2BJMmsh9pcPEHElu43UXFT8rB6TA2mxdjPMu62kCA%3D%3D--t25nJ%2BsxkyihjcJr--HSr650jOhPC4X1%2BSDBEOxg%3D%3D; Path=/; HttpOnly; Secure; SameSite=Lax
set-cookie: _octo=GH1.1.266826526.1753288163; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 16:29:23 GMT; Secure; SameSite=Lax
set-cookie: logged_in=no; Path=/; Domain=github.com; Expires=Thu, 23 Jul 2026 16:29:23 GMT; HttpOnly; Secure; SameSite=Lax
x-github-request-id: C7D4:D3350:EA4F72:114DCFF:68810DE3
HTTP client API changes for 0.5.0 · Issue #303 · ReactiveX/RxNetty · GitHub
No labelsNo typeNo projectsNone yetNo branches or pull requests
Skip to content
Navigation Menu
{{ message }}
-
Notifications
You must be signed in to change notification settings - Fork 257
Closed
Milestone
Description
This issue contains the API changes to HTTP client based on the issues #282 #280 #281
Http Client
All mutations to the client creates a new instance of the client.
public abstract class HttpClient<I, O> {
/**
* Creates a GET request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createGet(String uri);
/**
* Creates a POST request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createPost(String uri);
/**
* Creates a PUT request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createPut(String uri);
/**
* Creates a DELETE request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createDelete(String uri);
/**
* Creates a HEAD request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createHead(String uri);
/**
* Creates an OPTIONS request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createOptions(String uri);
/**
* Creates a PATCH request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createPatch(String uri);
/**
* Creates a TRACE request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createTrace(String uri);
/**
* Creates a CONNECT request for the passed URI.
*
* @param uri The URI for the request. The URI can be relative or absolute. If the URI is relative
* (missing host and port information), the target host and port are inferred from the {@link HttpClient}
* that created the request. If the URI is absolute, the host and port are used from the URI.
*
* @return New {@link HttpClientRequest}.
*/
public abstract HttpClientRequest<I, O> createConnect(String uri);
/**
* Creates a new client instances, inheriting all configurations from this client and adding the passed read timeout
* for all requests created by the newly created client instance.
*
* @param timeOut Read timeout duration.
* @param timeUnit Timeunit for the timeout.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> readTimeOut(int timeOut, TimeUnit timeUnit);
/**
* Creates a new client instances, inheriting all configurations from this client and following the passed number of
* max HTTP redirects.
*
* @param maxRedirects Maximum number of redirects to follow for any request.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> followRedirects(int maxRedirects);
/**
* Creates a new client instances, inheriting all configurations from this client and enabling/disabling redirects
* for all requests created by the newly created client instance.
*
* @param follow {@code true} to follow redirects. {@code false} to disable any redirects.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> followRedirects(boolean follow);
/**
* Creates a new client instances, inheriting all configurations from this client and adding a
* {@link ChannelOption} for the connections created by the newly created client instance.
*
* @param option Option to add.
* @param value Value for the option.
*
* @return A new {@link HttpClient} instance.
*/
public abstract <T> HttpClient<I, O> channelOption(ChannelOption<T> option, T value);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* action to configure all the connections created by the newly created client instance.
*
* @param pipelineConfigurator Action to configure {@link ChannelPipeline}.
*
* @return A new {@link HttpClient} instance.
*/
public abstract <II, OO> HttpClient<II, OO> pipelineConfigurator(Action1<ChannelPipeline> pipelineConfigurator);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* eventLoopGroup for all the connections created by the newly created client instance.
*
* @param eventLoopGroup {@link EventLoopGroup} to use.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> eventLoop(EventLoopGroup eventLoopGroup);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* {@code maxConnections} as the maximum number of concurrent connections created by the newly created client instance.
*
* @param maxConnections Maximum number of concurrent connections to be created by this client.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> maxConnections(int maxConnections);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* {@code idleConnectionsTimeoutMillis} as the time elapsed before an idle connections will be closed by the newly
* created client instance.
*
* @param idleConnectionsTimeoutMillis Time elapsed before an idle connections will be closed by the newly
* created client instance
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withIdleConnectionsTimeoutMillis(long idleConnectionsTimeoutMillis);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* {@code limitDeterminationStrategy} as the strategy to control the maximum concurrent connections created by the
* newly created client instance.
*
* @param limitDeterminationStrategy Strategy to control the maximum concurrent connections created by the
* newly created client instance.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withConnectionPoolLimitStrategy(PoolLimitDeterminationStrategy limitDeterminationStrategy);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* {@code poolIdleCleanupScheduler} for detecting and cleaning idle connections by the newly created client instance.
*
* @param poolIdleCleanupScheduler Scheduled to schedule idle connections cleanup.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withPoolIdleCleanupScheduler(ScheduledExecutorService poolIdleCleanupScheduler);
/**
* Creates a new client instances, inheriting all configurations from this client and disabling idle connection
* cleanup for the newly created client instance.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withNoIdleConnectionCleanup();
/**
* Creates a new client instances, inheriting all configurations from this client and disabling connection
* pooling for the newly created client instance.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withNoConnectionPooling();
/**
* Creates a new client instances, inheriting all configurations from this client and enabling wire logging at the
* passed level for the newly created client instance.
*
* @param wireLogginLevel Logging level at which the wire logs will be logged. The wire logging will only be done if
* logging is enabled at this level for {@link LoggingHandler}
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> enableWireLogging(LogLevel wireLogginLevel);
/**
* Creates a new client instances, inheriting all configurations from this client and using the passed
* {@code sslEngineFactory} for all secured connections created by the newly created client instance.
*
* @param sslEngineFactory {@link SSLEngineFactory} for all secured connections created by the newly created client
* instance.
*
* @return A new {@link HttpClient} instance.
*/
public abstract HttpClient<I, O> withSslEngineFactory(SSLEngineFactory sslEngineFactory);
}
Http Client Request
This folds HttpRequestHeaders
, ClientConfig
and ChannelPipeline
methods into the request.
Every mutation creates a new instance of the request. In order to do multiple mutations, the cost of creating intermediary request instances can be avoided by using HttpClientRequestUpdater
, created from this HttpClientRequest
using newUpdater()
method.
public abstract class HttpClientRequest<I, O> extends Observable<HttpClientResponse<O>>
implements HttpClientRequestOperations<I, HttpClientRequest<I, O>> {
protected HttpClientRequest(OnSubscribe<HttpClientResponse<O>> onSubscribe) {
super(onSubscribe);
}
/**
* Uses the passed {@link Observable} as the content source for the newly created and returned
* {@link HttpClientRequest}.
*
* @param contentSource Content source for the request.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setContentSource(Observable<I> contentSource);
/**
* Uses the passed {@link Observable} as the content source for the newly created and returned
* {@link HttpClientRequest}.
*
* @param rawContentSource Content source for the request.
* @param transformer Content transformer for the passed source.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract <S> HttpClientRequest<I, O> setRawContentSource(Observable<S> rawContentSource,
ContentTransformer<S> transformer);
/**
* Uses the passed {@code content} as the content for the newly created and returned
* {@link HttpClientRequest}. This is equivalent to calling
* {@code
* setRawContentSource(Observable.just(content), transformer);
* }
*
* @param content Content for the request.
* @param transformer Content transformer for the passed content.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract <S> HttpClientRequest<I, O> setRawContent(S content, ContentTransformer<S> transformer);
/**
* Uses the passed {@code content} as the content for the newly created and returned
* {@link HttpClientRequest}. This is equivalent to calling
* {@code
* setContentSource(Observable.just(content));
* }
*
* @param content Content for the request.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setContent(I content);
/**
* Uses the passed {@code content} as the content for the newly created and returned
* {@link HttpClientRequest}. This is equivalent to calling
* {@code
* setContent(content.getBytes(Charset.defaultCharset()));
* }
*
* @param content Content for the request.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setStringContent(String content);
/**
* Uses the passed {@code content} as the content for the newly created and returned
* {@link HttpClientRequest}. This is equivalent to calling
* {@code
* setRawContentSource(Observable.just(content), ByteTransformer.DEFAULT_INSTANCE);
* }
*
* @param content Content for the request.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setBytesContent(byte[] content);
/**
* Enables read timeout for the response of the newly created and returned request.
*
* @param timeOut Read timeout duration.
* @param timeUnit Read timeout time unit.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> readTimeOut(int timeOut, TimeUnit timeUnit);
/**
* Enables following HTTP redirects for the newly created and returned request.
*
* @param maxRedirects Maximum number of redirects allowed.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> followRedirects(int maxRedirects);
/**
* Enables/disables following HTTP redirects for the newly created and returned request.
*
* @param follow {@code true} for enabling redirects, {@code false} to disable.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> followRedirects(boolean follow);
/**
* Adds an HTTP header with the passed {@code name} and {@code value} to this request.
*
* @param name Name of the header.
* @param value Value for the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> addHeader(CharSequence name, Object value);
/**
* Adds the passed {@code cookie} to this request.
*
* @param cookie Cookie to add.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> addCookie(Cookie cookie);
/**
* Adds the passed header as a date value to this request. The date is formatted using netty's
* {@link HttpHeaders#addDateHeader(HttpMessage, CharSequence, Date)} which formats the date as per the
* <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">HTTP specifications</a> into the format:
*
<PRE>"E, dd MMM yyyy HH:mm:ss z"</PRE>
*
* @param name Name of the header.
* @param value Value of the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> addDateHeader(CharSequence name, Date value);
/**
* Adds multiple date values for the passed header name to this request. The date values are formatted using netty's
* {@link HttpHeaders#addDateHeader(HttpMessage, CharSequence, Date)} which formats the date as per the
* <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">HTTP specifications</a> into the format:
*
<PRE>"E, dd MMM yyyy HH:mm:ss z"</PRE>
*
* @param name Name of the header.
* @param values Values for the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> addDateHeader(CharSequence name, Iterable<Date> values);
/**
* Adds an HTTP header with the passed {@code name} and {@code values} to this request.
*
* @param name Name of the header.
* @param values Values for the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> addHeader(CharSequence name, Iterable<Object> values);
/**
* Overwrites the current value, if any, of the passed header to the passed date value for this request.
* The date is formatted using netty's {@link HttpHeaders#addDateHeader(HttpMessage, CharSequence, Date)} which
* formats the date as per the
* <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">HTTP specifications</a> into the format:
*
<PRE>"E, dd MMM yyyy HH:mm:ss z"</PRE>
*
* @param name Name of the header.
* @param value Value of the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setDateHeader(CharSequence name, Date value);
/**
* Overwrites the current value, if any, of the passed header to the passed value for this request.
*
* @param name Name of the header.
* @param value Value of the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setHeader(CharSequence name, Object value);
/**
* Overwrites the current value, if any, of the passed header to the passed date values for this request.
* The date is formatted using netty's {@link HttpHeaders#addDateHeader(HttpMessage, CharSequence, Date)} which
* formats the date as per the
* <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1">HTTP specifications</a> into the format:
*
<PRE>"E, dd MMM yyyy HH:mm:ss z"</PRE>
*
* @param name Name of the header.
* @param values Values of the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setDateHeader(CharSequence name, Iterable<Date> values);
/**
* Overwrites the current value, if any, of the passed header to the passed values for this request.
*
* @param name Name of the header.
* @param values Values of the header.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setHeader(CharSequence name, Iterable<Object> values);
/**
* Sets HTTP Connection header to the appropriate value for HTTP keep-alive.
* This delegates to {@link HttpHeaders#setKeepAlive(HttpMessage, boolean)}
*
* @param keepAlive {@code true} to enable keep alive.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setKeepAlive(boolean keepAlive);
/**
* Sets the HTTP transfer encoding to chunked for this request.
* This delegates to {@link HttpHeaders#setTransferEncodingChunked(HttpMessage)}
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
@Override
public abstract HttpClientRequest<I, O> setTransferEncodingChunked();
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added at the first position of the pipeline as specified by
* {@link ChannelPipeline#addFirst(String, ChannelHandler)}
*
* @param name Name of the handler.
* @param handler Handler instance to add.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerFirst(String name, ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added at the first position of the pipeline as specified by
* {@link ChannelPipeline#addFirst(EventExecutorGroup, String, ChannelHandler)}
*
* @param group the {@link EventExecutorGroup} which will be used to execute the {@link ChannelHandler}
* methods
* @param name the name of the handler to append
* @param handler the handler to append
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerFirst(EventExecutorGroup group, String name,
ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added at the last position of the pipeline as specified by
* {@link ChannelPipeline#addLast(String, ChannelHandler)}
*
* @param name Name of the handler.
* @param handler Handler instance to add.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerLast(String name, ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added at the last position of the pipeline as specified by
* {@link ChannelPipeline#addLast(EventExecutorGroup, String, ChannelHandler)}
*
* @param group the {@link EventExecutorGroup} which will be used to execute the {@link ChannelHandler}
* methods
* @param name the name of the handler to append
* @param handler the handler to append
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerLast(EventExecutorGroup group, String name,
ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added before an existing handler with the passed {@code baseName} in the pipeline as specified by
* {@link ChannelPipeline#addBefore(String, String, ChannelHandler)}
*
* @param baseName the name of the existing handler
* @param name Name of the handler.
* @param handler Handler instance to add.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerBefore(String baseName, String name,
ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added before an existing handler with the passed {@code baseName} in the pipeline as specified by
* {@link ChannelPipeline#addBefore(EventExecutorGroup, String, String, ChannelHandler)}
*
* @param group the {@link EventExecutorGroup} which will be used to execute the {@link ChannelHandler}
* methods
* @param baseName the name of the existing handler
* @param name the name of the handler to append
* @param handler the handler to append
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerBefore(EventExecutorGroup group, String baseName,
String name, ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added after an existing handler with the passed {@code baseName} in the pipeline as specified by
* {@link ChannelPipeline#addAfter(String, String, ChannelHandler)}
*
* @param baseName the name of the existing handler
* @param name Name of the handler.
* @param handler Handler instance to add.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerAfter(String baseName, String name,
ChannelHandler handler);
/**
* Adds a {@link ChannelHandler} to {@link ChannelPipeline} for the connection used by this request. The specified
* handler is added after an existing handler with the passed {@code baseName} in the pipeline as specified by
* {@link ChannelPipeline#addAfter(EventExecutorGroup, String, String, ChannelHandler)}
*
* @param group the {@link EventExecutorGroup} which will be used to execute the {@link ChannelHandler}
* methods
* @param baseName the name of the existing handler
* @param name the name of the handler to append
* @param handler the handler to append
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> addChannelHandlerAfter(EventExecutorGroup group, String baseName,
String name, ChannelHandler handler);
/**
* Configures an action to configure the {@link ChannelPipeline} for the connection used by this request.
*
* @param configurator Action that will be used to configure the pipeline.
*
* @return A new instance of the {@link HttpClientRequest} sharing all existing state from this request.
* Use {@link #newUpdater()} if you intend to do multiple mutations to this request, to avoid creating unused
* intermediary {@link HttpClientRequest} objects.
*/
public abstract <II, OO> HttpClientRequest<II, OO> withPipelineConfigurator(Action1<ChannelPipeline> configurator);
/**
* Checks whether a header with the passed name exists for this request.
*
* @param name Header name.
*
* @return {@code true} if the header exists.
*/
@Override
public abstract boolean containsHeader(CharSequence name);
/**
* Captures the current state of this request instance and creates a new {@link HttpClientRequestUpdater} to be used
* for performing multiple mutations to this request. Using {@link HttpClientRequestUpdater} avoids creating multiple
* intermediate and unused {@link HttpClientRequest} objects for each mutation.
*
* @return A new instance of {@link HttpClientRequestUpdater}
*/
public abstract HttpClientRequestUpdater<I, O> newUpdater();
/**
* Checks whether a header with the passed name and value exists for this request.
*
* @param name Header name.
* @param value Value to check.
* @param caseInsensitiveValueMatch If the value has to be matched ignoring case.
*
* @return {@code true} if the header with the passed value exists.
*/
@Override
public abstract boolean containsHeaderWithValue(CharSequence name, CharSequence value, boolean caseInsensitiveValueMatch);
/**
* Fetches the value of a header, if exists, for this request.
*
* @param name Name of the header.
*
* @return The value of the header, if it exists, {@code null} otherwise. If there are multiple values for this
* header, the first value is returned.
*/
@Override
public abstract String getHeader(CharSequence name);
/**
* Fetches all values of a header, if exists, for this request.
*
* @param name Name of the header.
*
* @return All values of the header, if it exists, {@code null} otherwise.
*/
@Override
public abstract List<String> getAllHeaders(CharSequence name);
/**
* Returns the HTTP version of this request.
*
* @return The HTTP version of this request.
*/
@Override
public abstract HttpVersion getHttpVersion();
/**
* Returns the HTTP method for this request.
*
* @return The HTTP method for this request.
*/
@Override
public abstract HttpMethod getMethod();
/**
* Returns the URI for this request.
* The returned URI does <em>not</em> contain the scheme, host and port portion of the URI. In case, it is required,
* {@link #getAbsoluteUri()} must be used.
*
* @return The URI for this request.
*/
@Override
public abstract String getUri();
/**
* Returns the absolute URI for this request including the scheme, host and port portion of the URI.
*
* @return The absolute URI for this request.
*/
@Override
public abstract String getAbsoluteUri();
}
Examples
Following are a few examples of how interaction with this client will be different than what it stands today.
Absolute URI & Hello World
RxNetty.newHttpClient().createGet("https://localhost:9999/hello") // Absolute URI, with host & port
.addHeader("X-New-Header", "blah")
.addCookie(new DefaultCookie("cookie1", "cookieval"))
.flatMap(response -> response.getContent())
.toBlocking()
.forEach(byteBuf -> System.out.println(byteBuf.toString(Charset.defaultCharset())));
Relative URI
newHttpClient("localhost", 7777).createGet("/hello") // Relative URI, host & port inferred from the client.
.flatMap(response -> response.getContent())
.toBlocking()
.forEach(byteBuf -> System.out.println(byteBuf.toString(Charset.defaultCharset())));
Override Host & Port
newHttpClient("localhost", 7777).createGet("https://www.mydomain.com:9999/hello") // Override host & port in the URI.
.flatMap(response -> response.getContent())
.toBlocking()
.forEach(byteBuf -> System.out.println(byteBuf.toString(Charset.defaultCharset())));
Updating pipeline
newHttpClient().createGet("https://localhost:8888/helloWorld")
.addHeader("X-New-Header", "blah")
.<ByteBuf, String>addChannelHandlerFirst("string-decoder", new SimpleChannelInboundHandler<ByteBuf>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
ctx.fireChannelRead(msg.toString(Charset.defaultCharset()));
}
}) // Updating the response content type.
.<String, String>addChannelHandlerFirst("string-encoder", new ChannelOutboundHandlerAdapter() {
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
throws Exception {
if (msg instanceof String) {
ctx.write(ctx.alloc().buffer().writeBytes(((String) msg).getBytes()));
}
}
}) // Updating the request content type.
.setContent("Hello World") // Using the updated request content type as string.
.flatMap(response -> response.getContent())
.toBlocking()
.forEach(System.out::println); // Since the response is now a string, printing it as is.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Issue actions
You can’t perform that action at this time.