public class NettyHttp2Client extends Object
An HTTP2 client that allows you to send HTTP2 frames to a server using HTTP1-style approaches
(via InboundHttp2ToHttpAdapter). Inbound and outbound
frames are logged.
When run from the command-line, sends a single HEADERS frame to the server and gets back
a "Hello World" response.
See the ./http2/helloworld/frame/client/ example for a HTTP2 client example which does not use
HTTP1-style objects and patterns.
1. 包协议
+-----------------------------------------------------------------------------+
| Length (24) 帧总长度 |
+---------------+---------------+---------------------------------------------+
| Type (8) Http2FrameTypes | Flags (8) Http2Flags |
+-+-------------+---------------+-------------------------------------------+
|R 保留字段 | Stream Identifier (31) Http2FrameStream.id() |
+=+===========================================================------------==+
| Frame Payload (0...) ...不同的FrameTypes类型,不同的字段.Http2Frame |
+---------------------------------------------------------------------------+
Length:帧有效载荷的长度,表示为无符号的24位整数。除非接收方为SETTINGS_MAX_FRAME_SIZE设置了较大的值,否则不得发送大于2 ^ 14(16,384)的值。帧头的9个八位字节不包含在该值中。
Type:帧的8位类型。帧类型决定帧的格式和语义。实现必须忽略并丢弃任何类型未知的帧。
Flags:为帧类型专用的布尔标志保留的8位字段。标志被分配特定于指定帧类型的语义。没有为特定帧类型定义语义的标志务必被忽略,并且在发送时务必保持未设置(0x0)。
R:保留的1位字段。该位的语义是未定义的,并且该位必须在发送时保持未设置(0x0),并且在接收时必须忽略。
Stream Identifier:流标识符 表示为一个无符号的31位整数。值0x0保留给与整个连接相关联的帧,而不是单个流。
详情参看RFC标准 https://www.rfc-editor.org/rfc/pdfrfc/rfc7540.txt.pdf
(这个类型位由服务端返回, 告诉客户端, 这个包是什么类型),
(这个状态位由服务端返回, 告诉客户端, 是否结束header, 是否结束body)| 限定符和类型 | 类和说明 |
|---|---|
static interface |
NettyHttp2Client.H2FutureListener |
static class |
NettyHttp2Client.H2Response |
static class |
NettyHttp2Client.Http2Handler
Configures the client pipeline to support HTTP/2 frames.
|
static class |
NettyHttp2Client.Http2SettingsHandler |
static class |
NettyHttp2Client.HttpResponseHandler
Process
FullHttpResponse translated from HTTP/2 frames |
| 构造器和说明 |
|---|
NettyHttp2Client(String domain) |
NettyHttp2Client(URL domain) |
NettyHttp2Client(URL domain,
io.netty.channel.EventLoopGroup worker) |
| 限定符和类型 | 方法和说明 |
|---|---|
NettyHttp2Client |
awaitConnect() |
NettyHttp2Client |
awaitConnect(int connectTimeout) |
void |
checkTimeout() |
io.netty.util.concurrent.Promise<Long> |
close() |
io.netty.util.concurrent.Promise<Long> |
close(boolean shutdownWorker) |
io.netty.util.concurrent.Promise<Long> |
close(boolean shutdownWorker,
String closeCause) |
io.netty.util.concurrent.Promise<io.netty.channel.Channel> |
connect() |
NettyHttp2Client |
connectTimeout(int connectTimeout) |
io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> |
flush() |
io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> |
flush(io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> promise) |
long |
getBeginConnectTimestamp() |
int |
getConnectTimeout() |
long |
getEndConnectTimestamp() |
long |
getMaxContentLength() |
InetSocketAddress |
getRemoteAddress() |
int |
getRequestTimeout() |
io.netty.handler.codec.http2.Http2Settings |
getSettings() |
Map<Integer,NettyHttp2Client.H2Response> |
getStreamIdPromiseMap() |
io.netty.util.concurrent.ScheduledFuture<?> |
getTimeoutScheduledFuture() |
URL |
getUrl() |
boolean |
isActive() |
boolean |
isClose() |
boolean |
isSsl() |
NettyHttp2Client |
logger(io.netty.handler.logging.LogLevel logLevel) |
static void |
main(String[] args) |
NettyHttp2Client |
maxContentLength(int maxContentLength) |
NettyHttp2Client |
maxPendingSize(int maxPendingSize) |
void |
onHttp2Connect(io.netty.channel.ChannelFuture future,
io.netty.util.concurrent.Promise<io.netty.channel.Channel> connectPromise) |
void |
onHttp2Setting(NettyHttp2Client.Http2SettingsHandler settingsHandler,
io.netty.channel.ChannelFuture future,
io.netty.util.concurrent.Promise<io.netty.channel.Channel> connectPromise) |
NettyHttp2Client |
requestTimeout(int requestTimeout) |
io.netty.util.concurrent.ScheduledFuture |
scheduleTimeoutCheck(int timeoutCheckScheduleInterval,
TimeUnit timeUnit) |
static io.netty.util.ResourceLeakDetector.Level |
setMemoryLeakDetector(io.netty.util.ResourceLeakDetector.Level level) |
NettyHttp2Client |
timeoutCheckScheduleInterval(int timeoutCheckScheduleInterval) |
String |
toString() |
NettyHttp2Client.H2Response |
write(io.netty.handler.codec.http.FullHttpRequest request)
用完需要使用者主动释放内存,不然会内存泄漏
ReferenceCounted.release() |
NettyHttp2Client.H2Response |
write(io.netty.handler.codec.http.FullHttpRequest request,
int requestTimeout)
用完需要使用者主动释放内存,不然会内存泄漏
ReferenceCounted.release() |
NettyHttp2Client.H2Response |
writeAndFlush(io.netty.handler.codec.http.FullHttpRequest request)
用完需要使用者主动释放内存,不然会内存泄漏
ReferenceCounted.release() |
NettyHttp2Client.H2Response |
writeAndFlush(io.netty.handler.codec.http.FullHttpRequest request,
int requestTimeout)
用完需要使用者主动释放内存,不然会内存泄漏
ReferenceCounted.release() |
public NettyHttp2Client(String domain) throws SSLException, MalformedURLException, UnknownHostException
public NettyHttp2Client(URL domain) throws SSLException, UnknownHostException
public NettyHttp2Client(URL domain, io.netty.channel.EventLoopGroup worker) throws UnknownHostException, SSLException
public static io.netty.util.ResourceLeakDetector.Level setMemoryLeakDetector(io.netty.util.ResourceLeakDetector.Level level)
public NettyHttp2Client requestTimeout(int requestTimeout)
public io.netty.util.concurrent.ScheduledFuture<?> getTimeoutScheduledFuture()
public int getRequestTimeout()
public NettyHttp2Client connectTimeout(int connectTimeout)
public int getConnectTimeout()
public NettyHttp2Client logger(io.netty.handler.logging.LogLevel logLevel)
public NettyHttp2Client maxContentLength(int maxContentLength)
public long getMaxContentLength()
public NettyHttp2Client maxPendingSize(int maxPendingSize)
public NettyHttp2Client awaitConnect() throws ConnectException
ConnectExceptionpublic NettyHttp2Client awaitConnect(int connectTimeout) throws ConnectException
ConnectExceptionpublic URL getUrl()
public long getBeginConnectTimestamp()
public long getEndConnectTimestamp()
public boolean isActive()
public io.netty.util.concurrent.Promise<io.netty.channel.Channel> connect()
public NettyHttp2Client timeoutCheckScheduleInterval(int timeoutCheckScheduleInterval)
public io.netty.util.concurrent.ScheduledFuture scheduleTimeoutCheck(int timeoutCheckScheduleInterval,
TimeUnit timeUnit)
public void checkTimeout()
public void onHttp2Connect(io.netty.channel.ChannelFuture future,
io.netty.util.concurrent.Promise<io.netty.channel.Channel> connectPromise)
public void onHttp2Setting(NettyHttp2Client.Http2SettingsHandler settingsHandler, io.netty.channel.ChannelFuture future, io.netty.util.concurrent.Promise<io.netty.channel.Channel> connectPromise) throws ConnectException
ConnectExceptionpublic NettyHttp2Client.H2Response write(io.netty.handler.codec.http.FullHttpRequest request, int requestTimeout)
ReferenceCounted.release()request - 请求requestTimeout - 超时时间, 小于0则永不超时 NettyHttp2Client.H2Response.isTimeout()public NettyHttp2Client.H2Response write(io.netty.handler.codec.http.FullHttpRequest request)
ReferenceCounted.release()request - 请求public NettyHttp2Client.H2Response writeAndFlush(io.netty.handler.codec.http.FullHttpRequest request)
ReferenceCounted.release()request - 请求public NettyHttp2Client.H2Response writeAndFlush(io.netty.handler.codec.http.FullHttpRequest request, int requestTimeout)
ReferenceCounted.release()request - 请求requestTimeout - 超时时间, 小于0则永不超时 NettyHttp2Client.H2Response.isTimeout()public io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> flush()
public boolean isClose()
public Map<Integer,NettyHttp2Client.H2Response> getStreamIdPromiseMap()
public io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> flush(io.netty.util.concurrent.Promise<List<NettyHttp2Client.H2Response>> promise)
public io.netty.util.concurrent.Promise<Long> close()
public io.netty.util.concurrent.Promise<Long> close(boolean shutdownWorker)
public io.netty.util.concurrent.Promise<Long> close(boolean shutdownWorker, String closeCause)
public boolean isSsl()
public InetSocketAddress getRemoteAddress()
public io.netty.handler.codec.http2.Http2Settings getSettings()
Copyright © 2021. All rights reserved.