Exemple #1
0
            protected override bool HandleProxyProtocol(IChannelHandlerContext ctx, object msg)
            {
                var req = (IFullHttpRequest)msg;
                IFullHttpResponse res;
                var sendGreeting = false;

                if (!_server.Authenticate(ctx, req))
                {
                    res = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.Unauthorized);
                    res.Headers.Set(HttpHeaderNames.ContentLength, 0);
                }
                else if (!req.Uri.Equals(((DnsEndPoint)_server.Destination).Host + ':' +
                                         ((DnsEndPoint)_server.Destination).Port))
                {
                    res = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.Forbidden);
                    res.Headers.Set(HttpHeaderNames.ContentLength, 0);
                }
                else
                {
                    res          = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.OK);
                    sendGreeting = true;
                }

                ctx.WriteAsync(res);
                ctx.Pipeline.Get <HttpServerCodec>().RemoveOutboundHandler();

                if (sendGreeting)
                {
                    ctx.WriteAsync(Unpooled.CopiedBuffer("0\n", Encoding.ASCII));
                }

                return(true);
            }
Exemple #2
0
            protected override bool HandleProxyProtocol(IChannelHandlerContext ctx, object msg)
            {
                var req = (IFullHttpRequest)msg;
                IFullHttpResponse res;

                if (!_server.Authenticate(ctx, req))
                {
                    res = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.Unauthorized);
                    res.Headers.Set(HttpHeaderNames.ContentLength, 0);
                }
                else
                {
                    res = new DefaultFullHttpResponse(HttpVersion.Http11, HttpResponseStatus.OK);
                    var uri          = req.Uri;
                    var lastColonPos = uri.LastIndexOf(':');
                    Assert.True(lastColonPos > 0);
                    IntermediaryDestination = new DnsEndPoint(uri.Substring(0, lastColonPos),
                                                              int.Parse(uri.Substring(lastColonPos + 1)));
                }

                ctx.WriteAsync(res);
                ctx.Pipeline.Get <HttpServerCodec>().RemoveOutboundHandler();
                return(true);
            }