Skip to content

Commit

Permalink
Immutable local/remote SocketAddress within a ConnectionMetaData
Browse files Browse the repository at this point in the history
The local/remote SocketAddress is cached within the ConnectionMetaData or Connection instance, so that any changes are not visible during the request lifetime.
Ensure that all server Connection types respect HttpConfiguration#getLocalAddress and that it is not implemented only in servlet layer
Avoid DNS resolution.
  • Loading branch information
gregw committed Nov 10, 2023
1 parent 8ae73ad commit 72df5cb
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class ServerFCGIConnection extends AbstractMetaDataConnection implements

public ServerFCGIConnection(Connector connector, EndPoint endPoint, HttpConfiguration configuration, boolean sendStatus200)
{
super(connector, endPoint, connector.getExecutor(), configuration);
super(connector, configuration, endPoint);
this.connector = connector;
this.networkByteBufferPool = connector.getByteBufferPool();
this.flusher = new Flusher(endPoint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ public SocketAddress getLocalSocketAddress()
try
{
SelectableChannel channel = getChannel();
if (channel instanceof NetworkChannel)
return ((NetworkChannel)channel).getLocalAddress();
if (channel instanceof NetworkChannel networkChannel)
return networkChannel.getLocalAddress();
return null;
}
catch (Throwable x)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package org.eclipse.jetty.server;

import java.net.SocketAddress;
import java.util.concurrent.Executor;

import org.eclipse.jetty.io.AbstractConnection;
import org.eclipse.jetty.io.Connection;
Expand All @@ -31,9 +30,9 @@ public abstract class AbstractMetaDataConnection extends AbstractConnection impl
private final SocketAddress _localSocketAddress;
private final SocketAddress _remoteSocketAddress;

public AbstractMetaDataConnection(Connector connector, EndPoint endPoint, Executor executor, HttpConfiguration httpConfiguration)
public AbstractMetaDataConnection(Connector connector, HttpConfiguration httpConfiguration, EndPoint endPoint)
{
super(endPoint, executor);
super(endPoint, connector.getExecutor());
_connector = connector;
_httpConfiguration = httpConfiguration;
_localSocketAddress = httpConfiguration.getLocalAddress() != null ? httpConfiguration.getLocalAddress() : endPoint.getLocalSocketAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected static HttpConnection setCurrentConnection(HttpConnection connection)

public HttpConnection(HttpConfiguration configuration, Connector connector, EndPoint endPoint, boolean recordComplianceViolations)
{
super(connector, endPoint, connector.getExecutor(), configuration);
super(connector, configuration, endPoint);
_id = __connectionIdGenerator.getAndIncrement();
_bufferPool = connector.getByteBufferPool();
_generator = newHttpGenerator();
Expand Down

0 comments on commit 72df5cb

Please sign in to comment.