use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.
the class AbstractNettyHandler method sendInitialConnectionWindow.
/**
* Sends initial connection window to the remote endpoint if necessary.
*/
private void sendInitialConnectionWindow() throws Http2Exception {
if (!initialWindowSent && ctx.channel().isActive()) {
Http2Stream connectionStream = connection().connectionStream();
int currentSize = connection().local().flowController().windowSize(connectionStream);
int delta = initialConnectionWindow - currentSize;
decoder().flowController().incrementWindowSize(connectionStream, delta);
initialWindowSent = true;
ctx.flush();
}
}
use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.
the class Http2ControlFrameLimitEncoder method handleOutstandingControlFrames.
private ChannelPromise handleOutstandingControlFrames(ChannelHandlerContext ctx, ChannelPromise promise) {
if (!limitReached) {
if (outstandingControlFrames == maxOutstandingControlFrames) {
// Let's try to flush once as we may be able to flush some of the control frames.
ctx.flush();
}
if (outstandingControlFrames == maxOutstandingControlFrames) {
limitReached = true;
Http2Exception exception = Http2Exception.connectionError(Http2Error.ENHANCE_YOUR_CALM, "Maximum number %d of outstanding control frames reached", maxOutstandingControlFrames);
logger.info("Maximum number {} of outstanding control frames reached. Closing channel {}", maxOutstandingControlFrames, ctx.channel(), exception);
// First notify the Http2LifecycleManager and then close the connection.
lifecycleManager.onError(ctx, true, exception);
ctx.close();
}
outstandingControlFrames++;
// once the promise was completed
return promise.unvoid().addListener(outstandingControlFramesListener);
}
return promise;
}
use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.
the class UtilsTest method testStatusFromThrowable.
@Test
public void testStatusFromThrowable() {
Status s = Status.CANCELLED.withDescription("msg");
assertSame(s, Utils.statusFromThrowable(new Exception(s.asException())));
Throwable t;
t = new ConnectTimeoutException("msg");
assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t));
t = new UnresolvedAddressException();
assertStatusEquals(Status.UNAVAILABLE.withCause(t), Utils.statusFromThrowable(t));
t = new Http2Exception(Http2Error.INTERNAL_ERROR, "msg");
assertStatusEquals(Status.INTERNAL.withCause(t), Utils.statusFromThrowable(t));
t = new Exception("msg");
assertStatusEquals(Status.UNKNOWN.withCause(t), Utils.statusFromThrowable(t));
}
use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.
the class GrpcHttp2HeadersUtilsTest method decode_requestHeaders.
@Test
public void decode_requestHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ServerHeadersDecoder(DEFAULT_MAX_HEADER_LIST_SIZE);
Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
Http2Headers headers = new DefaultHttp2Headers(false);
headers.add(of(":scheme"), of("https")).add(of(":method"), of("GET")).add(of(":path"), of("index.html")).add(of(":authority"), of("foo.grpc.io")).add(of("custom"), of("header"));
encodedHeaders = Unpooled.buffer();
encoder.encodeHeaders(1, /* randomly chosen */
headers, encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
encodedHeaders);
assertEquals(headers.get(of(":scheme")), decodedHeaders.scheme());
assertEquals(headers.get(of(":method")), decodedHeaders.method());
assertEquals(headers.get(of(":path")), decodedHeaders.path());
assertEquals(headers.get(of(":authority")), decodedHeaders.authority());
assertEquals(headers.get(of("custom")), decodedHeaders.get(of("custom")));
assertEquals(headers.size(), decodedHeaders.size());
String toString = decodedHeaders.toString();
assertContainsKeyAndValue(toString, ":scheme", decodedHeaders.scheme());
assertContainsKeyAndValue(toString, ":method", decodedHeaders.method());
assertContainsKeyAndValue(toString, ":path", decodedHeaders.path());
assertContainsKeyAndValue(toString, ":authority", decodedHeaders.authority());
assertContainsKeyAndValue(toString, "custom", decodedHeaders.get(of("custom")));
}
use of io.netty.handler.codec.http2.Http2Exception in project grpc-java by grpc.
the class GrpcHttp2HeadersUtilsTest method decode_emptyHeaders.
@Test
public void decode_emptyHeaders() throws Http2Exception {
Http2HeadersDecoder decoder = new GrpcHttp2ClientHeadersDecoder(8192);
Http2HeadersEncoder encoder = new DefaultHttp2HeadersEncoder(NEVER_SENSITIVE);
ByteBuf encodedHeaders = Unpooled.buffer();
encoder.encodeHeaders(1, /* randomly chosen */
new DefaultHttp2Headers(false), encodedHeaders);
Http2Headers decodedHeaders = decoder.decodeHeaders(3, /* randomly chosen */
encodedHeaders);
assertEquals(0, decodedHeaders.size());
assertThat(decodedHeaders.toString()).contains("[]");
}
Aggregations