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

Let ConnectionFactory see difference between proxied and direct connections #2169

Merged

Conversation

idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Mar 31, 2022

Motivation:
The connection initialization sequence is different for secure HTTP proxy
tunnels. It's necessary for the ConnectionFactory and
TransportObserver to know if the newConnection(...) is being invoked for
a regular connection or a proxy tunnel in order to correctly count timing
of events.

Modifications:

  • Introduce new HttpContextKeys#HTTP_TARGET_ADDRESS_BEHIND_PROXY key;
  • Enhance ProxyConnectConnectionFactoryFilter and
    AbsoluteAddressHttpRequesterFilter to fill in the value for
    HTTP_TARGET_ADDRESS_BEHIND_PROXY;
  • Enhance proxy tests to verify that the key value always present;

Result:

Users can distinguish attempts to open direct connections and
connections through a proxy.

Depends on #2168, review starting from the 2nd commit.

@idelpivnitskiy idelpivnitskiy self-assigned this Mar 31, 2022
@idelpivnitskiy idelpivnitskiy changed the title Allow ConnectionFactory see difference between proxied and direct connections Allow ConnectionFactory to see difference between proxied and direct connections Mar 31, 2022
@idelpivnitskiy idelpivnitskiy changed the title Allow ConnectionFactory to see difference between proxied and direct connections Let ConnectionFactory see difference between proxied and direct connections Mar 31, 2022
Single<C> newConnection(ResolvedAddress address, @Nullable TransportObserver observer);
default Single<C> newConnection(ResolvedAddress address, @Nullable ContextMap context,
@Nullable TransportObserver observer) { // FIXME: 0.43 - remove default impl
return Single.defer(() -> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will the implementation be when Connection factory implementations override this method? Are they to implement the defer and the addition of the key to the context?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the defer here is only necessary to "glue" the old overload with DeprecatedToNewConnectionFactoryFilter. If users implement this method, it's expected that they will invoke the same method in delegate chain, skipping the AsyncContext dance and directly propagating the context to the next filter.

/**
* Default implementation of {@link ContextMap}.
* <p>
* Note: it's not concurrent!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose better wording would be "it's not thread-safe".

Motivation:

Connection initialization sequence is different for a secure HTTP proxy
tunnels.  It's necessary for the `ConnectionFactory` and
`TransportObserver` to know if the `newConnection` is invoked for a
regular connection or a proxy tunnel in order to correctly count timing
of events.

Modifications:

- Introduce new `HttpContextKeys#HTTP_TARGET_ADDRESS_BEHIND_PROXY` key;
- Enhance `ProxyConnectConnectionFactoryFilter` and
`AbsoluteAddressHttpRequesterFilter` to fill the value for
`HTTP_TARGET_ADDRESS_BEHIND_PROXY`;
- Enhance proxy tests to verify that the key value always present;

Result:

Users can distinguish attempts to open direct connections and
connections through a proxy.
@idelpivnitskiy idelpivnitskiy force-pushed the HTTP_TARGET_ADDRESS_BEHIND_PROXY branch from 7104d9a to cae941b Compare April 13, 2022 15:25
@idelpivnitskiy idelpivnitskiy merged commit 071666f into apple:main Apr 13, 2022
@idelpivnitskiy idelpivnitskiy deleted the HTTP_TARGET_ADDRESS_BEHIND_PROXY branch April 13, 2022 15:45
idelpivnitskiy added a commit to idelpivnitskiy/servicetalk that referenced this pull request Oct 2, 2023
Motivation:

Prior to `ConnectionObserver.ProxyConnectObserver` added in apple#2711, the
sequence of `ConnectionObserver` events was different between regular
connections and connection to the proxy tunnels.
`HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` (apple#2169) was useful to
distinguish when the correct callback inside `ConnectionObserver` before
reporting that a new connection is ready to take traffic.
After adding `ProxyConnectObserver`, there is no need in this custom
key.

Modifications:

- Deprecate `HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` and
describe what is an appropriate replacement for users;

Result:

We will be able to remove
`HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` in the future
releases.
idelpivnitskiy added a commit that referenced this pull request Oct 3, 2023
Motivation:

Prior to `ConnectionObserver.ProxyConnectObserver` added in #2711, the
sequence of `ConnectionObserver` events was different between regular
connections and connection to the proxy tunnels.
`HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` (#2169) was useful to
distinguish when the correct callback inside `ConnectionObserver` before
reporting that a new connection is ready to take traffic.
After adding `ProxyConnectObserver`, there is no need in this custom
key.

Modifications:

- Deprecate `HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` and
describe what is an appropriate replacement for users;

Result:

We will be able to remove
`HttpContextKeys.HTTP_TARGET_ADDRESS_BEHIND_PROXY` in the future
releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants