diff --git a/core/src/main/java/io/undertow/server/protocol/proxy/ProxyProtocolReadListener.java b/core/src/main/java/io/undertow/server/protocol/proxy/ProxyProtocolReadListener.java index 4dd07dbaae..6315e55bc2 100644 --- a/core/src/main/java/io/undertow/server/protocol/proxy/ProxyProtocolReadListener.java +++ b/core/src/main/java/io/undertow/server/protocol/proxy/ProxyProtocolReadListener.java @@ -37,7 +37,7 @@ class ProxyProtocolReadListener implements ChannelListener private static final byte[] NAME = "PROXY ".getBytes(StandardCharsets.US_ASCII); 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 final StreamConnection streamConnection; @@ -136,7 +136,7 @@ public void handleEvent(StreamSourceChannel streamSourceChannel) { stringBuilder.setLength(0); if (protocol.equals(UNKNOWN)) { parsingUnknown = true; - } else if (!protocol.equals(TCP) && !protocol.equals(TCP_6)) { + } else if (!protocol.equals(TCP4) && !protocol.equals(TCP_6)) { throw UndertowMessages.MESSAGES.invalidProxyHeader(); } } else if (sourceAddress == null) { @@ -234,7 +234,7 @@ private void callOpenListener(StreamConnection streamConnection, final PooledByt } static InetAddress parseAddress(String addressString, String protocol) throws IOException { - if (protocol.equals(TCP)) { + if (protocol.equals(TCP4)) { return NetworkUtils.parseIpv4Address(addressString); } else { return NetworkUtils.parseIpv6Address(addressString); diff --git a/core/src/test/java/io/undertow/server/protocol/proxy/ProxyProtocolTestCase.java b/core/src/test/java/io/undertow/server/protocol/proxy/ProxyProtocolTestCase.java index 45a6442af0..ad83733bc4 100644 --- a/core/src/test/java/io/undertow/server/protocol/proxy/ProxyProtocolTestCase.java +++ b/core/src/test/java/io/undertow/server/protocol/proxy/ProxyProtocolTestCase.java @@ -41,7 +41,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception { undertow.start(); int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort(); 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()); Assert.assertTrue(result, result.contains("result: /1.2.3.4:444 /5.6.7.8:555")); } finally { @@ -72,7 +72,7 @@ public void handleRequest(HttpServerExchange exchange) throws Exception { undertow.start(); int port = ((InetSocketAddress) undertow.getListenerInfo().get(0).getAddress()).getPort(); 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.getOutputStream().write("GET / HTTP/1.0\r\n\r\n".getBytes(StandardCharsets.US_ASCII)); String result = FileUtils.readFile(s.getInputStream());