本文整理汇总了Java中io.netty.handler.codec.http2.HttpConversionUtil类的典型用法代码示例。如果您正苦于以下问题:Java HttpConversionUtil类的具体用法?Java HttpConversionUtil怎么用?Java HttpConversionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpConversionUtil类属于io.netty.handler.codec.http2包,在下文中一共展示了HttpConversionUtil类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getHttpRequest
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
public FullHttpRequest getHttpRequest() {
if (h1Request != null) {
return h1Request;
}
if (h2Headers != null) {
try {
// Fake out a full HTTP request.
FullHttpRequest synthesizedRequest =
HttpConversionUtil.toFullHttpRequest(0, h2Headers, alloc, true);
if (data != null) {
synthesizedRequest.replace(data);
}
return synthesizedRequest;
} catch (Http2Exception e) {
// TODO(JR): Do something more meaningful with this exception
e.printStackTrace();
}
}
throw new IllegalStateException("Cannot get the http request for an empty XrpcRequest");
}
开发者ID:Nordstrom,项目名称:xrpc,代码行数:24,代码来源:XrpcRequest.java
示例2: channelRead
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
LOGGER.info("[Client ({})] => [Server ({})] : {}",
connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
msg);
if (msg instanceof FullHttpRequest) {
String streamId = ((HttpRequest) msg).headers().get(
HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
if (streamId == null) {
throw new IllegalStateException("No streamId");
}
streams.offer(streamId);
} else if (msg instanceof HttpObject) {
throw new IllegalStateException("Cannot handle message: " + msg.getClass());
}
outboundChannel.writeAndFlush(msg);
}
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:20,代码来源:Http2FrontendHandler.java
示例3: write
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
LOGGER.info("[Client ({})] <= [Server ({})] : {}",
connectionInfo.getClientAddr(), connectionInfo.getServerAddr(),
msg);
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
if (!response.headers().contains(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text())) {
if (streams.isEmpty()) {
throw new IllegalStateException("No active streams");
}
response.headers().add(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(),
streams.poll());
}
}
ctx.write(msg, promise);
}
开发者ID:chhsiao90,项目名称:nitmproxy,代码行数:20,代码来源:Http2FrontendHandler.java
示例4: channelRead0
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
Integer streamId = msg.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
if (streamId == null) {
System.err.println("HttpResponseHandler unexpected message received: " + msg);
return;
}
Entry<ChannelFuture, ChannelPromise> entry = streamidPromiseMap.get(streamId);
if (entry == null) {
System.err.println("Message received for unknown stream id " + streamId);
} else {
// Do stuff with the message (for now just print it)
ByteBuf content = msg.content();
if (content.isReadable()) {
int contentLength = content.readableBytes();
byte[] arr = new byte[contentLength];
content.readBytes(arr);
System.out.println(new String(arr, 0, contentLength, CharsetUtil.UTF_8));
}
entry.getValue().setSuccess();
}
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:25,代码来源:HttpResponseHandler.java
示例5: channelRead0
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
Integer streamId = msg.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
if (streamId == null) {
log.error("HTTP2ResponseHandler unexpected message received: " + msg);
return;
}
Entry<ChannelFuture, ChannelPromise> entry = streamIdPromiseMap.get(streamId);
if (entry == null) {
if (streamId == 1) {
log.error("HTTP2 Upgrade request has received from stream : " + streamId);
}
} else {
ByteBuf content = msg.content();
if (content.isReadable()) {
int contentLength = content.readableBytes();
byte[] arr = new byte[contentLength];
content.readBytes(arr);
streamIdResponseMap.put(streamId, new String(arr, 0, contentLength, CharsetUtil.UTF_8));
}
entry.getValue().setSuccess();
}
}
开发者ID:wso2,项目名称:carbon-transports,代码行数:24,代码来源:HTTP2ResponseHandler.java
示例6: push
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
public void push(final String method, final String path, final Map<String, Object> headers) {
ctx.channel().eventLoop().execute(() -> {
AsciiString streamIdHeader = HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text();
Http2Connection connection = encoder.connection();
int nextStreamId = connection.local().incrementAndGetNextStreamId();
Http2Headers h2headers = new DefaultHttp2Headers()
.path(path)
.method(method)
.authority(authority)
.scheme(scheme);
headers.forEach((n, v) -> h2headers.add(n, v.toString()));
encoder.writePushPromise(ctx, streamId, nextStreamId, h2headers, 0, ctx.newPromise());
// TODO: Is there another way of handling a push promise?
DefaultFullHttpRequest pushRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.valueOf(method.toUpperCase()), path, Unpooled.EMPTY_BUFFER,
new DefaultHttpHeaders(false).set(streamIdHeader, nextStreamId),
EmptyHttpHeaders.INSTANCE);
ctx.pipeline().fireChannelRead(pushRequest);
ctx.pipeline().fireChannelReadComplete();
});
}
开发者ID:jooby-project,项目名称:jooby,代码行数:24,代码来源:NettyPush.java
示例7: channelRead0
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Http2Settings) {
settingsPromise.setSuccess(null);
return;
}
if (msg instanceof FullHttpResponse) {
FullHttpResponse res = (FullHttpResponse) msg;
Integer streamId = res.headers().getInt(
HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
if (streamId == null) {
responsePromise.tryFailure(new AssertionError("message without stream ID: " + msg));
return;
}
if (streamId == 1) {
// Response to the upgrade request, which is OK to ignore.
return;
}
if (streamId != 3) {
responsePromise.tryFailure(new AssertionError("unexpected stream ID: " + msg));
return;
}
responsePromise.setSuccess(res.content().retain());
return;
}
throw new IllegalStateException("unexpected message type: " + msg.getClass().getName());
}
开发者ID:line,项目名称:armeria,代码行数:33,代码来源:THttp2Client.java
示例8: send
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
public int send(FullHttpRequest request) throws Exception {
// Configure ssl.
int currentStreamId = streamId.addAndGet(2);
request.headers().add(HttpHeaderNames.HOST, hostName);
request.headers().add(HttpConversionUtil.ExtensionHeaderNames.SCHEME.text(), scheme.name());
responseHandler.put(currentStreamId, channel.write(request), channel.newPromise());
channel.flush();
log.info("Finished HTTP/2 request");
return currentStreamId;
}
开发者ID:wso2,项目名称:carbon-transports,代码行数:12,代码来源:HTTP2Client.java
示例9: status
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
public HttpResponseStatus status() {
try {
return HttpConversionUtil.parseStatus(delegate.status());
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:xjdr,项目名称:xio,代码行数:8,代码来源:StreamingHttp2Response.java
示例10: status
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
/**
* Throws a RuntimeException if the underlying status cannot be converted to an HttpResponseStatus
*/
@Override
public HttpResponseStatus status() {
try {
return HttpConversionUtil.parseStatus(delegate.status());
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:xjdr,项目名称:xio,代码行数:12,代码来源:FullHttp2Response.java
示例11: http1Headers
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
/** Return an Http1 Headers object based on the values in the underlying Http2Headers object. */
@Override
public HttpHeaders http1Headers(boolean isTrailer, boolean isRequest) {
try {
HttpHeaders headers = new DefaultHttpHeaders();
HttpConversionUtil.addHttp2ToHttpHeaders(
-1, delegate, headers, HttpVersion.HTTP_1_1, isTrailer, isRequest);
return headers;
} catch (Http2Exception e) {
throw new RuntimeException(e);
}
}
开发者ID:xjdr,项目名称:xio,代码行数:13,代码来源:Http2HeadersWrapper.java
示例12: NettyResponse
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
public NettyResponse(final ChannelHandlerContext ctx, final int bufferSize,
final boolean keepAlive, final String streamId) {
this.ctx = ctx;
this.bufferSize = bufferSize;
this.keepAlive = keepAlive;
this.headers = new DefaultHttpHeaders();
if (streamId != null) {
headers.set(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), streamId);
}
this.status = HttpResponseStatus.OK;
}
开发者ID:jooby-project,项目名称:jooby,代码行数:12,代码来源:NettyResponse.java
示例13: upgrade
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T upgrade(final Class<T> type) throws Exception {
if (type == NativeWebSocket.class) {
String protocol = ifSecure("wss", "ws");
String webSocketURL = protocol + "://" + req.headers().get(HttpHeaderNames.HOST) + path;
WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(
webSocketURL, null, true, wsMaxMessageSize);
WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
NettyWebSocket result = new NettyWebSocket(ctx, handshaker, (ws) -> {
handshaker.handshake(ctx.channel(), (FullHttpRequest) req)
.addListener(FIRE_EXCEPTION_ON_FAILURE)
.addListener(payload -> ws.connect())
.addListener(FIRE_EXCEPTION_ON_FAILURE);
});
ctx.channel().attr(NettyWebSocket.KEY).set(result);
return (T) result;
} else if (type == Sse.class) {
NettySse sse = new NettySse(ctx);
return (T) sse;
} else if (type == NativePushPromise.class) {
return (T) new NettyPush(ctx,
req.headers().getInt(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text()),
header("host").orElse(ip()), ifSecure("https", "http"));
}
throw new UnsupportedOperationException("Not Supported: " + type);
}
开发者ID:jooby-project,项目名称:jooby,代码行数:29,代码来源:NettyRequest.java
示例14: streamId
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
private String streamId(FullHttpRequest request) {
return request.headers().get(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
}
开发者ID:cowthan,项目名称:JavaAyo,代码行数:4,代码来源:Http2RequestHandler.java
示例15: streamId
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
private String streamId(FullHttpRequest request) {
return request.headers().get(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text());
}
开发者ID:leogomes,项目名称:http2-netty,代码行数:4,代码来源:Http2RequestHandler.java
示例16: setStreamId
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
private void setStreamId(FullHttpResponse response, String streamId) {
response.headers().set(HttpConversionUtil.ExtensionHeaderNames.STREAM_ID.text(), streamId);
}
开发者ID:leogomes,项目名称:http2-netty,代码行数:4,代码来源:Http2RequestHandler.java
示例17: http2Headers
import io.netty.handler.codec.http2.HttpConversionUtil; //导入依赖的package包/类
@Override
public Http2Headers http2Headers() {
return HttpConversionUtil.toHttp2Headers(delegate, true);
}
开发者ID:xjdr,项目名称:xio,代码行数:5,代码来源:Http1Headers.java
注:本文中的io.netty.handler.codec.http2.HttpConversionUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论