Skip to content
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

Closed

Conversation

joakime
Copy link
Contributor

@joakime joakime commented Dec 14, 2021

Uses a Connection.Listener to set the override on connections that are opened using an HttpChannel.

@joakime joakime requested review from sbordet and gregw December 14, 2021 16:26
@joakime joakime self-assigned this Dec 14, 2021
@joakime joakime added Enhancement Specification For all industry Specifications (IETF / Servlet / etc) labels Dec 14, 2021
@joakime joakime requested a review from sbordet December 14, 2021 17:52
@joakime
Copy link
Contributor Author

joakime commented Dec 14, 2021

@sbordet changes applied

@joakime joakime changed the title Issue #7277 - Allow Request.getLocalName() to be overridden Issue #7277 - Allow Request.getLocalName() and .getLocalPort() to be overridden Dec 16, 2021
@joakime joakime requested a review from sbordet December 16, 2021 19:49
@joakime joakime added the Sponsored This issue affects a user with a commercial support agreement label Dec 16, 2021
Comment on lines +309 to +312
public HostPort getLocalAuthority()
{
return _localAuthority;
}
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Comment on lines +331 to +334
InetSocketAddress local = getLocalAddress();
if (local != null)
return local.getHostString();

Copy link
Contributor

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.

Copy link
Contributor Author

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.

* @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()
Copy link
Contributor

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

Comment on lines 1047 to 1049
InetSocketAddress local = _channel.getLocalAddress();
if (local != null)
return local.getPort();
Copy link
Contributor

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)

Copy link
Contributor Author

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]>
+ Breaks ResponseTest.testSendRedirect() expectations

Signed-off-by: Joakim Erdfelt <[email protected]>
@gregw
Copy link
Contributor

gregw commented Dec 20, 2021

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 ServerConnector server connector can achieve pretty much the same result.

@joakime
Copy link
Contributor Author

joakime commented Dec 20, 2021

This PR replaced with PR #7316

@joakime joakime closed this Jan 5, 2022
@joakime joakime deleted the jetty-9.4.x-7277-override-request-server-name branch February 11, 2022 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Specification For all industry Specifications (IETF / Servlet / etc) Sponsored This issue affects a user with a commercial support agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow override of ServletRequest.getLocalName() and .getLocalPort() in post-intermediary scenarios
3 participants