static ConnectionInfo parseForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; String forwarded = request.headers().get(FORWARDED_HEADER).split(",")[0]; Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded); if (hostMatcher.find()) { hostAddress = parseAddress(hostMatcher.group(1), hostAddress.getPort()); } Matcher protoMatcher = FORWARDED_PROTO_PATTERN.matcher(forwarded); if (protoMatcher.find()) { scheme = protoMatcher.group(1).trim(); } Matcher forMatcher = FORWARDED_FOR_PATTERN.matcher(forwarded); if(forMatcher.find()) { remoteAddress = parseAddress(forMatcher.group(1).trim(), remoteAddress.getPort()); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
static ConnectionInfo parseForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; String forwarded = request.headers().get(FORWARDED_HEADER).split(",")[0]; Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded); if (hostMatcher.find()) { hostAddress = parseAddress(hostMatcher.group(1), hostAddress.getPort()); } Matcher protoMatcher = FORWARDED_PROTO_PATTERN.matcher(forwarded); if (protoMatcher.find()) { scheme = protoMatcher.group(1).trim(); } Matcher forMatcher = FORWARDED_FOR_PATTERN.matcher(forwarded); if(forMatcher.find()) { remoteAddress = parseAddress(forMatcher.group(1).trim(), remoteAddress.getPort()); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; if (request.headers().contains(XFORWARDED_IP_HEADER)) { String remoteIpValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0]; remoteAddress = parseAddress(remoteIpValue, remoteAddress.getPort()); } if(request.headers().contains(XFORWARDED_HOST_HEADER)) { if(request.headers().contains(XFORWARDED_PORT_HEADER)) { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), Integer.parseInt(request.headers().get(XFORWARDED_PORT_HEADER).split(",")[0].trim())); } else { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), channel.localAddress().getPort()); } } if (request.headers().contains(XFORWARDED_PROTO_HEADER)) { scheme = request.headers().get(XFORWARDED_PROTO_HEADER).trim(); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }
static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel channel) { InetSocketAddress hostAddress = channel.localAddress(); InetSocketAddress remoteAddress = channel.remoteAddress(); String scheme = channel.pipeline().get(SslHandler.class) != null ? "https" : "http"; if (request.headers().contains(XFORWARDED_IP_HEADER)) { String remoteIpValue = request.headers().get(XFORWARDED_IP_HEADER).split(",")[0]; remoteAddress = parseAddress(remoteIpValue, remoteAddress.getPort()); } if(request.headers().contains(XFORWARDED_HOST_HEADER)) { if(request.headers().contains(XFORWARDED_PORT_HEADER)) { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), Integer.parseInt(request.headers().get(XFORWARDED_PORT_HEADER).split(",")[0].trim())); } else { hostAddress = InetSocketAddressUtil.createUnresolved( request.headers().get(XFORWARDED_HOST_HEADER).split(",")[0].trim(), channel.localAddress().getPort()); } } if (request.headers().contains(XFORWARDED_PROTO_HEADER)) { scheme = request.headers().get(XFORWARDED_PROTO_HEADER).trim(); } return new ConnectionInfo(hostAddress, remoteAddress, scheme); }