Java Code Examples for io.netty.channel.socket.SocketChannel#localAddress()

The following examples show how to use io.netty.channel.socket.SocketChannel#localAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectionInfo.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
static ConnectionInfo parseForwardedInfo(String forwardedHeader, SocketChannel channel, boolean secured,
		InetSocketAddress remoteAddress) {
	InetSocketAddress hostAddress = channel.localAddress();
	String scheme = secured ? "https" : "http";

	String forwarded = forwardedHeader.split(",", 2)[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);
}
 
Example 2
Source File: ConnectionInfo.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the connection information from the current connection directly
 * @param c the current channel
 * @param secured is transport secure (SSL)
 * @return the connection information
 */
static ConnectionInfo newConnectionInfo(Channel c, boolean secured, InetSocketAddress remoteAddress) {
	SocketChannel channel = (SocketChannel) c;
	InetSocketAddress hostAddress = channel.localAddress();
	String scheme = secured ? "https" : "http";
	return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}
 
Example 3
Source File: ConnectionInfo.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
static ConnectionInfo parseXForwardedInfo(HttpRequest request, SocketChannel channel, boolean secured,
		InetSocketAddress remoteAddress) {
	InetSocketAddress hostAddress = channel.localAddress();
	String scheme = secured ? "https" : "http";
	String ipHeader = request.headers().get(XFORWARDED_IP_HEADER);
	if (ipHeader != null) {
		remoteAddress = parseAddress(ipHeader.split(",", 2)[0], remoteAddress.getPort());
	}
	String hostHeader = request.headers().get(XFORWARDED_HOST_HEADER);
	if (hostHeader != null) {
		String portHeader = request.headers().get(XFORWARDED_PORT_HEADER);
		if (portHeader != null) {
			int port;
			try {
				port = Integer.parseInt(portHeader.split(",", 2)[0].trim());
			}
			catch (NumberFormatException e) {
				log.debug(format(channel, "Invalid value [" + portHeader + "] for the header [X-Forwarded-Port]"));
				port = hostAddress.getPort();
			}
			hostAddress = AddressUtils.createUnresolved(
					hostHeader.split(",", 2)[0].trim(), port);
		}
		else {
			hostAddress = AddressUtils.createUnresolved(
					hostHeader.split(",", 2)[0].trim(),
					hostAddress.getPort());
		}
	}
	String protoHeader = request.headers().get(XFORWARDED_PROTO_HEADER);
	if (protoHeader != null) {
		scheme = protoHeader.split(",", 2)[0].trim();
	}
	return new ConnectionInfo(hostAddress, remoteAddress, scheme);
}
 
Example 4
Source File: BasicClient.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
protected CC initRemoteConnection(SocketChannel channel){
  local=channel.localAddress();
  remote=channel.remoteAddress();
  return null;
}
 
Example 5
Source File: BasicServer.java    From Bats with Apache License 2.0 4 votes vote down vote up
@Override
protected SC initRemoteConnection(SocketChannel channel) {
  local = channel.localAddress();
  remote = channel.remoteAddress();
  return null;
}