Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
470311 - Introduce a proxy-protocol module.
Support for the PROXY protocol is now enabled via 2 new modules: proxy-protocol and proxy-protocol-ssl, respectively for the HTTP connector and the SSL connector.
- Loading branch information
Showing
13 changed files
with
326 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/ProxyProtocolTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// ======================================================================== | ||
// Copyright (c) 1995-2015 Mort Bay Consulting Pty. Ltd. | ||
// ------------------------------------------------------------------------ | ||
// All rights reserved. This program and the accompanying materials | ||
// are made available under the terms of the Eclipse Public License v1.0 | ||
// and Apache License v2.0 which accompanies this distribution. | ||
// | ||
// The Eclipse Public License is available at | ||
// http://www.eclipse.org/legal/epl-v10.html | ||
// | ||
// The Apache License v2.0 is available at | ||
// http://www.opensource.org/licenses/apache2.0.php | ||
// | ||
// You may elect to redistribute this code under either of these licenses. | ||
// ======================================================================== | ||
// | ||
|
||
package org.eclipse.jetty.http2.client; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.SocketChannel; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.CountDownLatch; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.eclipse.jetty.http.HttpFields; | ||
import org.eclipse.jetty.http.HttpStatus; | ||
import org.eclipse.jetty.http.HttpURI; | ||
import org.eclipse.jetty.http.HttpVersion; | ||
import org.eclipse.jetty.http.MetaData; | ||
import org.eclipse.jetty.http2.api.Session; | ||
import org.eclipse.jetty.http2.api.Stream; | ||
import org.eclipse.jetty.http2.frames.HeadersFrame; | ||
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory; | ||
import org.eclipse.jetty.server.Handler; | ||
import org.eclipse.jetty.server.HttpConfiguration; | ||
import org.eclipse.jetty.server.ProxyConnectionFactory; | ||
import org.eclipse.jetty.server.Request; | ||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.server.ServerConnector; | ||
import org.eclipse.jetty.server.handler.AbstractHandler; | ||
import org.eclipse.jetty.util.FuturePromise; | ||
import org.eclipse.jetty.util.Promise; | ||
import org.junit.After; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ProxyProtocolTest | ||
{ | ||
private Server server; | ||
private ServerConnector connector; | ||
private HTTP2Client client; | ||
|
||
public void startServer(Handler handler) throws Exception | ||
{ | ||
server = new Server(); | ||
HttpConfiguration configuration = new HttpConfiguration(); | ||
connector = new ServerConnector(server, new ProxyConnectionFactory(), new HTTP2CServerConnectionFactory(configuration)); | ||
server.addConnector(connector); | ||
server.setHandler(handler); | ||
|
||
client = new HTTP2Client(); | ||
server.addBean(client, true); | ||
|
||
server.start(); | ||
} | ||
|
||
@After | ||
public void dispose() throws Exception | ||
{ | ||
if (server != null) | ||
server.stop(); | ||
} | ||
|
||
@Test | ||
public void test_PROXY_GET() throws Exception | ||
{ | ||
startServer(new AbstractHandler() | ||
{ | ||
@Override | ||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException | ||
{ | ||
baseRequest.setHandled(true); | ||
} | ||
}); | ||
|
||
String request1 = "PROXY TCP4 1.2.3.4 5.6.7.8 1111 2222\r\n"; | ||
SocketChannel channel = SocketChannel.open(); | ||
channel.connect(new InetSocketAddress("localhost", connector.getLocalPort())); | ||
channel.write(ByteBuffer.wrap(request1.getBytes(StandardCharsets.UTF_8))); | ||
|
||
FuturePromise<Session> promise = new FuturePromise<>(); | ||
client.accept(null, channel, new Session.Listener.Adapter(), promise); | ||
Session session = promise.get(5, TimeUnit.SECONDS); | ||
|
||
HttpFields fields = new HttpFields(); | ||
String uri = "http://localhost:" + connector.getLocalPort() + "/"; | ||
MetaData.Request metaData = new MetaData.Request("GET", new HttpURI(uri), HttpVersion.HTTP_2, fields); | ||
HeadersFrame frame = new HeadersFrame(1, metaData, null, true); | ||
CountDownLatch latch = new CountDownLatch(1); | ||
session.newStream(frame, new Promise.Adapter<>(), new Stream.Listener.Adapter() | ||
{ | ||
@Override | ||
public void onHeaders(Stream stream, HeadersFrame frame) | ||
{ | ||
MetaData.Response response = (MetaData.Response)frame.getMetaData(); | ||
Assert.assertEquals(HttpStatus.OK_200, response.getStatus()); | ||
if (frame.isEndStream()) | ||
latch.countDown(); | ||
} | ||
}); | ||
Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
jetty-server/src/main/config/etc/jetty-proxy-protocol-ssl.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0"?> | ||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd"> | ||
|
||
<Configure id="sslConnector" class="org.eclipse.jetty.server.ServerConnector"> | ||
<Call name="addFirstConnectionFactory"> | ||
<Arg> | ||
<New class="org.eclipse.jetty.server.ProxyConnectionFactory"/> | ||
</Arg> | ||
</Call> | ||
</Configure> |
Oops, something went wrong.