mirror of https://github.com/grpc/grpc-java.git
parent
89bc2cd3b2
commit
aa0391a427
|
|
@ -91,6 +91,10 @@ public final class ProtocolNegotiators {
|
||||||
class PlaintextHandler extends ChannelHandlerAdapter implements Handler {
|
class PlaintextHandler extends ChannelHandlerAdapter implements Handler {
|
||||||
@Override
|
@Override
|
||||||
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
|
||||||
|
// Set sttributes before replace to be sure we pass it before accepting any requests.
|
||||||
|
handler.handleProtocolNegotiationCompleted(Attributes.newBuilder()
|
||||||
|
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
|
||||||
|
.build());
|
||||||
// Just replace this handler with the gRPC handler.
|
// Just replace this handler with the gRPC handler.
|
||||||
ctx.pipeline().replace(this, null, handler);
|
ctx.pipeline().replace(this, null, handler);
|
||||||
}
|
}
|
||||||
|
|
@ -155,6 +159,7 @@ public final class ProtocolNegotiators {
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION,
|
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION,
|
||||||
sslHandler(ctx.pipeline()).engine().getSession())
|
sslHandler(ctx.pipeline()).engine().getSession())
|
||||||
|
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
|
||||||
.build());
|
.build());
|
||||||
// Replace this handler with the GRPC handler.
|
// Replace this handler with the GRPC handler.
|
||||||
ctx.pipeline().replace(this, null, grpcHandler);
|
ctx.pipeline().replace(this, null, grpcHandler);
|
||||||
|
|
@ -509,6 +514,7 @@ public final class ProtocolNegotiators {
|
||||||
grpcHandler.handleProtocolNegotiationCompleted(
|
grpcHandler.handleProtocolNegotiationCompleted(
|
||||||
Attributes.newBuilder()
|
Attributes.newBuilder()
|
||||||
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION, handler.engine().getSession())
|
.set(Grpc.TRANSPORT_ATTR_SSL_SESSION, handler.engine().getSession())
|
||||||
|
.set(Grpc.TRANSPORT_ATTR_REMOTE_ADDR, ctx.channel().remoteAddress())
|
||||||
.build());
|
.build());
|
||||||
writeBufferedAndRemove(ctx);
|
writeBufferedAndRemove(ctx);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -335,7 +335,7 @@ public class NettyClientTransportTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void clientStreamGetsSslSessionAttributes() throws Exception {
|
public void clientStreamGetsAttributes() throws Exception {
|
||||||
startServer();
|
startServer();
|
||||||
NettyClientTransport transport = newTransport(newNegotiator());
|
NettyClientTransport transport = newTransport(newNegotiator());
|
||||||
transport.start(clientTransportListener);
|
transport.start(clientTransportListener);
|
||||||
|
|
@ -343,6 +343,7 @@ public class NettyClientTransportTest {
|
||||||
rpc.waitForResponse();
|
rpc.waitForResponse();
|
||||||
|
|
||||||
assertNotNull(rpc.stream.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION));
|
assertNotNull(rpc.stream.getAttributes().get(Grpc.TRANSPORT_ATTR_SSL_SESSION));
|
||||||
|
assertEquals(address, rpc.stream.getAttributes().get(Grpc.TRANSPORT_ATTR_REMOTE_ADDR));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Throwable getRootCause(Throwable t) {
|
private Throwable getRootCause(Throwable t) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue