Skip to content

Commit

Permalink
UNDERTOW-1288 Undertow not accepting value TCP4 for INET_PROTOCOL in …
Browse files Browse the repository at this point in the history
…proxy protocol header
  • Loading branch information
stuartwdouglas committed Feb 21, 2018
1 parent 6d42509 commit 29475c0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Expand Up @@ -37,7 +37,7 @@ class ProxyProtocolReadListener implements ChannelListener<StreamSourceChannel>


private static final byte[] NAME = "PROXY ".getBytes(StandardCharsets.US_ASCII); private static final byte[] NAME = "PROXY ".getBytes(StandardCharsets.US_ASCII);
private static final String UNKNOWN = "UNKNOWN"; private static final String UNKNOWN = "UNKNOWN";
private static final String TCP = "TCP"; private static final String TCP4 = "TCP4";
private static final String TCP_6 = "TCP6"; private static final String TCP_6 = "TCP6";


private final StreamConnection streamConnection; private final StreamConnection streamConnection;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void handleEvent(StreamSourceChannel streamSourceChannel) {
stringBuilder.setLength(0); stringBuilder.setLength(0);
if (protocol.equals(UNKNOWN)) { if (protocol.equals(UNKNOWN)) {
parsingUnknown = true; parsingUnknown = true;
} else if (!protocol.equals(TCP) && !protocol.equals(TCP_6)) { } else if (!protocol.equals(TCP4) && !protocol.equals(TCP_6)) {
throw UndertowMessages.MESSAGES.invalidProxyHeader(); throw UndertowMessages.MESSAGES.invalidProxyHeader();
} }
} else if (sourceAddress == null) { } else if (sourceAddress == null) {
Expand Down Expand Up @@ -234,7 +234,7 @@ private void callOpenListener(StreamConnection streamConnection, final PooledByt
} }


static InetAddress parseAddress(String addressString, String protocol) throws IOException { static InetAddress parseAddress(String addressString, String protocol) throws IOException {
if (protocol.equals(TCP)) { if (protocol.equals(TCP4)) {
return NetworkUtils.parseIpv4Address(addressString); return NetworkUtils.parseIpv4Address(addressString);
} else { } else {
return NetworkUtils.parseIpv6Address(addressString); return NetworkUtils.parseIpv6Address(addressString);
Expand Down
Expand Up @@ -41,7 +41,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
undertow.start(); undertow.start();
int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort(); int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort();
Socket s = new Socket(DefaultServer.getHostAddress(), port); Socket s = new Socket(DefaultServer.getHostAddress(), port);
s.getOutputStream().write("PROXY TCP 1.2.3.4 5.6.7.8 444 555\r\nGET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.US_ASCII)); s.getOutputStream().write("PROXY TCP4 1.2.3.4 5.6.7.8 444 555\r\nGET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.US_ASCII));
String result = FileUtils.readFile(s.getInputStream()); String result = FileUtils.readFile(s.getInputStream());
Assert.assertTrue(result, result.contains("result: /1.2.3.4:444 /5.6.7.8:555")); Assert.assertTrue(result, result.contains("result: /1.2.3.4:444 /5.6.7.8:555"));
} finally { } finally {
Expand Down Expand Up @@ -72,7 +72,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
undertow.start(); undertow.start();
int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort(); int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort();
Socket s = new Socket(DefaultServer.getHostAddress(), port); Socket s = new Socket(DefaultServer.getHostAddress(), port);
s.getOutputStream().write("PROXY TCP 1.2.3.4 5.6.7.8 444 555\r\n".getBytes(StandardCharsets.US_ASCII)); s.getOutputStream().write("PROXY TCP4 1.2.3.4 5.6.7.8 444 555\r\n".getBytes(StandardCharsets.US_ASCII));
s = DefaultServer.getClientSSLContext().getSocketFactory().createSocket(s, DefaultServer.getHostAddress(), port, true); s = DefaultServer.getClientSSLContext().getSocketFactory().createSocket(s, DefaultServer.getHostAddress(), port, true);
s.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.US_ASCII)); s.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.US_ASCII));
String result = FileUtils.readFile(s.getInputStream()); String result = FileUtils.readFile(s.getInputStream());
Expand Down

0 comments on commit 29475c0

Please sign in to comment.