APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http

pack-priv abstract Class HttpConnection

extends Object
implements Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable
Known Direct Subclasses
jdk.internal.net.http.HttpQuicConnection, jdk.internal.net.http.PlainHttpConnection, jdk.internal.net.http.PlainTunnelingConnection, jdk.internal.net.http.AbstractAsyncSSLConnection
Imports
java.io.Closeable, .IOException, java.net.InetSocketAddress, java.net.http.HttpResponse, .HttpClient.Version, .HttpHeaders, java.nio.ByteBuffer, java.nio.channels.NetworkChannel, .SocketChannel, java.util.Comparator, .IdentityHashMap, .List, .Map, java.util.concurrent.CompletableFuture, .CompletionStage, .ConcurrentLinkedDeque, .Flow, java.util.concurrent.atomic.AtomicLong, java.util.function.BiPredicate, javax.net.ssl.SNIServerName, jdk.internal.net.http.common.Alpns, .Demand, .FlowTube, .Logger, .SequentialScheduler, .SequentialScheduler.DeferredCompleter, .Log, .Utils

Wraps socket channel layer and takes care of SSL also. Subtypes are: PlainHttpConnection: regular direct TCP connection to server PlainProxyConnection: plain text proxy connection PlainTunnelingConnection: opens plain text (CONNECT) tunnel to server AsyncSSLConnection: TLS channel direct to server AsyncSSLTunnelConnection: TLS channel via (CONNECT) proxy tunnel HttpQuicConnection: direct QUIC connection to server

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
pack-priv class
HttpConnection.PlainHttpPublisher

A publisher that makes it possible to publish (write) ordered (normal priority) and unordered (high priority) buffers downstream.

private static class

Field Summary

Modifier and TypeField and Description
pack-priv final InetSocketAddress
address

The address this connection is connected to.

private final HttpClientImpl
public static final Comparator<HttpConnection>
pack-priv String
pack-priv final Logger
pack-priv static final Logger
private final long
id

A unique identifier that provides a total order among instances.

private final String
label

A label to identify the connection.

private static final AtomicLong
private final Origin
private final HttpConnection.TrailingOperations

Constructor Summary

AccessConstructor and Description
pack-priv
HttpConnection(Origin originServer, InetSocketAddress address, HttpClientImpl client, String label)

Method Summary

Modifier and TypeMethod and Description
pack-priv final InetSocketAddress
pack-priv final void
pack-priv abstract ConnectionPool.CacheKey
pack-priv abstract NetworkChannel
pack-priv boolean

Returns:

true if the channel appears to be still open.
checkOpen
()

Forces a call to the native implementation of the connection's channel to verify that this channel is still open.

pack-priv final HttpClientImpl
public abstract void
close()

Redeclares java.io.Closeable.close.

Closes this connection.

pack-priv abstract void
close(Throwable
the cause for which the connection is closed, may be null
cause
)

Closes this connection due to the given cause.

pack-priv void
public abstract CompletableFuture<Void>
connectAsync(Exchange<?> exchange)

Initiates the connect phase.

pack-priv abstract boolean
connected()

Tells whether, or not, this connection is connected to its destination.

pack-priv BiPredicate<String, String>
pack-priv final String
public abstract CompletableFuture<Void>
finishConnect()

Finishes the connection phase.

public static HttpConnection
getConnection(InetSocketAddress addr, HttpClientImpl client, Exchange<?> exchange, HttpRequestImpl request, HttpClient.Version version)

Factory for retrieving HttpConnections.

pack-priv abstract FlowTube

Returns:

the underlying connection flow, if applicable
getConnectionFlow
()

Returns the underlying connection flow, if applicable.

pack-priv final Origin

Returns:

the Origin server against which this connection communicates. Returns null if the connection is a plain connection to a proxy
getOriginServer
()

Returns the Origin server against which this connection communicates.

private static HttpConnection
public List<SNIServerName>

Returns:

the SNI server names
getSNIServerNames
()

Returns an unmodifiable list of SNIServerNames that were used during TLS handshake of this connection.

private static HttpConnection
pack-priv BiPredicate<String, String>
headerFilter(HttpRequestImpl request)

This method is used to build a filter that will accept or veto (header-name, value) tuple for transmission on the wire.

private long
id()

pack-priv boolean
isFlowFinished()

{@return true if the connection flow is finished.

pack-priv boolean
isOpen()

Tells whether, or not, this connection is open.

pack-priv abstract boolean
isProxied()

Tells whether, or not, this connection is proxied.

pack-priv abstract boolean
isSecure()

Tells whether, or not, this connection is secure ( over SSL )

pack-priv boolean
public final String

Returns:

a label identifying the connection to facilitate HttpResponse::connectionLabel
label
()

Returns a label identifying the connection to facilitate HttpResponse::connectionLabel.

pack-priv long
private static String
nextLabel(String prefix)

pack-priv abstract InetSocketAddress
proxy()

Returns the address of the proxy used by this connection.

private static Utils.ProxyHeaders
pack-priv abstract HttpConnection.HttpPublisher
publisher()

Returns the HTTP publisher associated with this connection.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

addressback to summary
pack-priv final InetSocketAddress address

The address this connection is connected to. Could be a server or a proxy.

clientback to summary
private final HttpClientImpl client
COMPARE_BY_IDback to summary
public static final Comparator<HttpConnection> COMPARE_BY_ID
dbgTagback to summary
pack-priv String dbgTag
debugback to summary
pack-priv final Logger debug
DEBUG_LOGGERback to summary
pack-priv static final Logger DEBUG_LOGGER
idback to summary
private final long id

A unique identifier that provides a total order among instances.

labelback to summary
private final String label

A label to identify the connection.

This label helps with associating multiple components participating in a connection. For instance, an AsyncSSLConnection and the PlainHttpConnection it wraps will share the same label.

LABEL_COUNTERback to summary
private static final AtomicLong LABEL_COUNTER
originServerback to summary
private final Origin originServer
trailingOperationsback to summary
private final HttpConnection.TrailingOperations trailingOperations

Constructor Detail

HttpConnectionback to summary
pack-priv HttpConnection(Origin originServer, InetSocketAddress address, HttpClientImpl client, String label)

Method Detail

addressback to summary
pack-priv final InetSocketAddress address()
addTrailingOperationback to summary
pack-priv final void addTrailingOperation(CompletionStage<?> cf)
cacheKeyback to summary
pack-priv abstract ConnectionPool.CacheKey cacheKey()
channelback to summary
pack-priv abstract NetworkChannel channel()
checkOpenback to summary
pack-priv boolean checkOpen()

Forces a call to the native implementation of the connection's channel to verify that this channel is still open.

This method should only be called just after an HTTP/1.1 connection is retrieved from the HTTP/1.1 connection pool. It is used to trigger an early detection of the channel state, before handling the connection over to the HTTP stack. It helps minimizing race conditions where the selector manager thread hasn't woken up - or hasn't raised the event, before the connection was retrieved from the pool. It helps reduce the occurrence of "HTTP/1.1 parser received no bytes" exception, when the server closes the connection while it's being taken out of the pool.

This method attempts to read one byte from the underlying channel. Because the connection was in the pool - there should be nothing to read.

If read manages to read a byte off the connection, this is a protocol error: the method closes the connection and returns false. If read returns EOF, the method closes the connection and returns false. If read throws an exception, the method returns false. Otherwise, read returns 0, the channel appears to be still open, and the method returns true.

Returns:boolean

true if the channel appears to be still open.

clientback to summary
pack-priv final HttpClientImpl client()
closeback to summary
public abstract void close()

Redeclares java.io.Closeable.close.

Closes this connection.

Annotations
@Override
closeback to summary
pack-priv abstract void close(Throwable cause)

Closes this connection due to the given cause.

Parameters
cause:Throwable

the cause for which the connection is closed, may be null

closeOrReturnToCacheback to summary
pack-priv void closeOrReturnToCache(HttpHeaders hdrs)
connectAsyncback to summary
public abstract CompletableFuture<Void> connectAsync(Exchange<?> exchange)

Initiates the connect phase. Returns a CompletableFuture that completes when the underlying TCP connection has been established or an error occurs.

connectedback to summary
pack-priv abstract boolean connected()

Tells whether, or not, this connection is connected to its destination.

contextRestrictedback to summary
pack-priv BiPredicate<String, String> contextRestricted(HttpRequestImpl request)
dbgStringback to summary
pack-priv final String dbgString()
finishConnectback to summary
public abstract CompletableFuture<Void> finishConnect()

Finishes the connection phase. Returns a CompletableFuture that completes when any additional, type specific, setup has been done. Must be called after connectAsync.

getConnectionback to summary
public static HttpConnection getConnection(InetSocketAddress addr, HttpClientImpl client, Exchange<?> exchange, HttpRequestImpl request, HttpClient.Version version)

Factory for retrieving HttpConnections. A connection can be retrieved from the connection pool, or a new one created if none available. The given addr is the ultimate destination. Any proxies, etc, are determined from the request. Returns a concrete instance which is one of the following: PlainHttpConnection PlainTunnelingConnection HttpQuicConnection The returned connection, if not from the connection pool, must have its, connect() or connectAsync() method invoked, which ( when it completes successfully ) renders the connection usable for requests.

getConnectionFlowback to summary
pack-priv abstract FlowTube getConnectionFlow()

Returns the underlying connection flow, if applicable.

API Note

TCP based protocols like HTTP/1.1 and HTTP/2 are built on top of a bidirectional connection flow. On the other hand, Quic based protocol like HTTP/3 are multiplexed at the Quic level, and therefore do not have a connection flow.

Returns:FlowTube

the underlying connection flow, if applicable

Exceptions
IllegalStateException:
if the underlying transport does not expose a single connection flow.
getOriginServerback to summary
pack-priv final Origin getOriginServer()

Returns the Origin server against which this connection communicates. Returns null if the connection is a plain connection to a proxy.

Returns:Origin

the Origin server against which this connection communicates. Returns null if the connection is a plain connection to a proxy

getPlainConnectionback to summary
private static HttpConnection getPlainConnection(InetSocketAddress addr, InetSocketAddress proxy, HttpRequestImpl request, HttpClientImpl client)
getSNIServerNamesback to summary
public List<SNIServerName> getSNIServerNames()

Returns an unmodifiable list of SNIServerNames that were used during TLS handshake of this connection. If this connection doesn't represent a TLS based connection or if no SNI server names were used during the handshake, then this method returns an empty list.

Returns:List<SNIServerName>

the SNI server names

getSSLConnectionback to summary
private static HttpConnection getSSLConnection(InetSocketAddress addr, InetSocketAddress proxy, String[] alpn, HttpRequestImpl request, HttpClientImpl client)
headerFilterback to summary
pack-priv BiPredicate<String, String> headerFilter(HttpRequestImpl request)

This method is used to build a filter that will accept or veto (header-name, value) tuple for transmission on the wire. The filter is applied to the headers when sending the headers to the remote party. Which tuple is accepted/vetoed depends on:

   - whether the connection is a tunnel connection
     [talking to a server through a proxy tunnel]
   - whether the method is CONNECT
     [establishing a CONNECT tunnel through a proxy]
   - whether the request is using a proxy
     (and the connection is not a tunnel)
     [talking to a server through a proxy]
   - whether the request is a direct connection to
     a server (no tunnel, no proxy).
idback to summary
private long id()
isFlowFinishedback to summary
pack-priv boolean isFlowFinished()

{@return true if the connection flow is finished.

isOpenback to summary
pack-priv boolean isOpen()

Tells whether, or not, this connection is open.

isProxiedback to summary
pack-priv abstract boolean isProxied()

Tells whether, or not, this connection is proxied. Returns true for tunnel connections, or clear connection to any host through proxy.

isSecureback to summary
pack-priv abstract boolean isSecure()

Tells whether, or not, this connection is secure ( over SSL )

isTunnelback to summary
pack-priv boolean isTunnel()
labelback to summary
public final String label()

Returns a label identifying the connection to facilitate HttpResponse::connectionLabel.

Returns:String

a label identifying the connection to facilitate HttpResponse::connectionLabel

newConnectionIdback to summary
pack-priv long newConnectionId(HttpClientImpl client)
nextLabelback to summary
private static String nextLabel(String prefix)
proxyback to summary
pack-priv abstract InetSocketAddress proxy()

Returns the address of the proxy used by this connection. Returns the proxy address for tunnel connections, or clear connection to any host through proxy. Returns null otherwise.

proxyTunnelHeadersback to summary
private static Utils.ProxyHeaders proxyTunnelHeaders(HttpRequestImpl request)
publisherback to summary
pack-priv abstract HttpConnection.HttpPublisher publisher()

Returns the HTTP publisher associated with this connection. May be null if invoked before connecting.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
jdk.internal.net.http back to summary

pack-priv Interface HttpConnection.HttpPublisher

extends TubePublisher
Known Direct Implementers
jdk.internal.net.http.HttpConnection.PlainHttpPublisher

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void

Method Detail

enqueueback to summary
public void enqueue(List<ByteBuffer> buffers) throws IOException
enqueueUnorderedback to summary
public void enqueueUnordered(List<ByteBuffer> buffers) throws IOException
signalEnqueuedback to summary
public void signalEnqueued() throws IOException
jdk.internal.net.http back to summary

pack-priv final Class HttpConnection.PlainHttpPublisher

extends Object
implements HttpPublisher
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.HttpConnection.HttpPublisher, jdk.internal.net.http.common.FlowTube.TubePublisher, java.util.concurrent.Flow.Publisher

A publisher that makes it possible to publish (write) ordered (normal priority) and unordered (high priority) buffers downstream.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
pack-priv final ConcurrentLinkedDeque<List<ByteBuffer>>
pack-priv final ConcurrentLinkedDeque<List<ByteBuffer>>
pack-priv final Object
pack-priv volatile Flow.Subscriber<? super List<ByteBuffer>>
pack-priv volatile HttpConnection.PlainHttpPublisher.HttpWriteSubscription
pack-priv final SequentialScheduler

Constructor Summary

AccessConstructor and Description
pack-priv
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
public void
pack-priv void
pack-priv void
public void
public void
subscribe(Flow.Subscriber<? super List<ByteBuffer>> subscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

priorityback to summary
pack-priv final ConcurrentLinkedDeque<List<ByteBuffer>> priority
queueback to summary
pack-priv final ConcurrentLinkedDeque<List<ByteBuffer>> queue
readingback to summary
pack-priv final Object reading
subscriberback to summary
pack-priv volatile Flow.Subscriber<? super List<ByteBuffer>> subscriber
subscriptionback to summary
pack-priv volatile HttpConnection.PlainHttpPublisher.HttpWriteSubscription subscription
writeSchedulerback to summary
pack-priv final SequentialScheduler writeScheduler

Constructor Detail

PlainHttpPublisherback to summary
pack-priv PlainHttpPublisher()
PlainHttpPublisherback to summary
pack-priv PlainHttpPublisher(Object readingLock)

Method Detail

enqueueback to summary
public void enqueue(List<ByteBuffer> buffers) throws IOException

Implements jdk.internal.net.http.HttpConnection.HttpPublisher.enqueue.

Annotations
@Override
enqueueUnorderedback to summary
public void enqueueUnordered(List<ByteBuffer> buffers) throws IOException

Implements jdk.internal.net.http.HttpConnection.HttpPublisher.enqueueUnordered.

Annotations
@Override
flushTaskback to summary
pack-priv void flushTask(SequentialScheduler.DeferredCompleter completer)
signalback to summary
pack-priv void signal()
signalEnqueuedback to summary
public void signalEnqueued() throws IOException

Implements jdk.internal.net.http.HttpConnection.HttpPublisher.signalEnqueued.

Annotations
@Override
subscribeback to summary
public void subscribe(Flow.Subscriber<? super List<ByteBuffer>> subscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Doc from java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber's onError method is invoked with an IllegalStateException. Otherwise, the Subscriber's onSubscribe method is invoked with a new Subscription. Subscribers may enable receiving items by invoking the request method of this Subscription, and may unsubscribe by invoking its cancel method.

Annotations
@Override
jdk.internal.net.http back to summary

pack-priv final Class HttpConnection.PlainHttpPublisher.HttpWriteSubscription

extends Object
implements Subscription
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.HttpConnection.PlainHttpPublisher.HttpWriteSubscription
All Implemented Interfaces
java.util.concurrent.Flow.Subscription

Field Summary

Modifier and TypeField and Description
pack-priv final Demand

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages.

pack-priv void
private boolean
private List<ByteBuffer>
poll()

public void
request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

demandback to summary
pack-priv final Demand demand

Constructor Detail

HttpWriteSubscriptionback to summary
pack-priv HttpWriteSubscription()

Method Detail

cancelback to summary
public void cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Doc from java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete or onError signal.

Annotations
@Override
flushback to summary
pack-priv void flush()
isEmptyback to summary
private boolean isEmpty()
pollback to summary
private List<ByteBuffer> poll()
requestback to summary
public void request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Doc from java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription. If n is less than or equal to zero, the Subscriber will receive an onError signal with an IllegalArgumentException argument. Otherwise, the Subscriber will receive up to n additional onNext invocations (or fewer if terminated).

Annotations
@Override
jdk.internal.net.http back to summary

private final Class HttpConnection.TrailingOperations

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final Map<CompletionStage<?>, Boolean>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

operationsback to summary
private final Map<CompletionStage<?>, Boolean> operations

Constructor Detail

TrailingOperationsback to summary
private TrailingOperations()

Method Detail

addback to summary
pack-priv void add(CompletionStage<?> cf)
removeback to summary
pack-priv boolean remove(CompletionStage<?> cf)