-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue #7277 - Allow Request.getLocalName()
and .getLocalPort()
to be overridden
#7283
Issue #7277 - Allow Request.getLocalName()
and .getLocalPort()
to be overridden
#7283
Conversation
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannelLocalNameOverrideListener.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Joakim Erdfelt <[email protected]>
@sbordet changes applied |
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/Request.java
Outdated
Show resolved
Hide resolved
jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Request.getLocalName()
to be overriddenRequest.getLocalName()
and .getLocalPort()
to be overridden
Signed-off-by: Joakim Erdfelt <[email protected]>
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
Outdated
Show resolved
Hide resolved
public HostPort getLocalAuthority() | ||
{ | ||
return _localAuthority; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should always return a local authority, either one set explicitly or one that is determined dynamically in doStart
(or open
).
Then the layers about can just ask for the authority and not have to check if null and then look at the address etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also make this a method on NetworkConnector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a NetworkConnector specific concept.
We have UnixDomainConnector and LocalConnector that can benefit from setLocalAuthority() and are not network connectors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot "always return a local authority".
I tried it.
Going this route breaks expectations in ForwardRequestCustomizer and DetectorConnection and ProxyEndPoint behaviors, so I reverted it.
InetSocketAddress local = getLocalAddress(); | ||
if (local != null) | ||
return local.getHostString(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never fall through to here. If there Connector
is a NetworkConnector
it should always provide a local authority, otherwise return null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above about this feature not being NetworkConnector specific.
jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java
Outdated
Show resolved
Hide resolved
* @return the local name if overridden, or the local address, or | ||
* null in the case of no local address (usually seen in connectors not based on IP networking). | ||
*/ | ||
public String getLocalName() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep the getLocalAuthority()
here and only convert to host/port in Request
InetSocketAddress local = _channel.getLocalAddress(); | ||
if (local != null) | ||
return local.getPort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have to do this fall back yet again here. Either is a local authority (so we have a port) or there is not (and we don't)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried this.
Going this route breaks expectations in ForwardRequestCustomizer and DetectorConnection and ProxyEndPoint behaviors, so I reverted it.
Signed-off-by: Joakim Erdfelt <[email protected]>
+ Breaks ... - DetectorConnectionTest - ProxyEndPoint - ForwardedRequestCustomizerTest Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
+ Breaks ResponseTest.testSendRedirect() expectations Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
Signed-off-by: Joakim Erdfelt <[email protected]>
I can make all but the EmptyHost test pass on an unmodified jetty-9 with the following ammendment to the unit test: private CloseableServer startServer(HostPort localAuthority) throws Exception
{
Server server = new Server();
ServerConnector connector;
if (localAuthority == null)
{
connector = new ServerConnector(server);
}
else
{
InetSocketAddress authorityInetSocketAddress = InetSocketAddress.createUnresolved(localAuthority.getHost(), localAuthority.getPort());
connector = new ServerConnector(server)
{
@Override
protected ChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey key) throws IOException
{
SocketChannelEndPoint endpoint = new SocketChannelEndPoint(channel, selectSet, key, getScheduler())
{
@Override
public InetSocketAddress getLocalAddress()
{
return authorityInetSocketAddress;
}
};
endpoint.setIdleTimeout(getIdleTimeout());
return endpoint;
}
};
}
connector.setPort(0); So I'm really reluctant to make big changes in jetty-9 when a simple extention of |
This PR replaced with PR #7316 |
Uses a Connection.Listener to set the override on connections that are opened using an
HttpChannel
.