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

Remove client address #280

Merged
merged 2 commits into from
Sep 17, 2018
Merged

Remove client address #280

merged 2 commits into from
Sep 17, 2018

Conversation

kvosper
Copy link
Contributor

@kvosper kvosper commented Sep 12, 2018

Implements #275

@dvlato dvlato changed the title Remove client address Remove client address (#275) Sep 12, 2018
@dvlato dvlato changed the title Remove client address (#275) Remove client address ( Fixes #275) Sep 12, 2018
@dvlato dvlato changed the title Remove client address ( Fixes #275) Remove client address Sep 12, 2018
@Override
public Optional<InetSocketAddress> clientAddress() {
return Optional.empty();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @kvosper I notice InetSocketAddress is an Optional. Under what circumstances it is absent? Can you remind me? Apart from unit tests I cannot think of any situation where client address wouldn't be available in the Context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we use the Styx client, there is a line host.hostClient().handle(request, new HttpInterceptorContext()). This requires a context because hostClient returns an HttpHandler, however clientAddress is not available in StyxHttpClient (nor it is relevant).

Copy link
Contributor

Choose a reason for hiding this comment

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

I see.

* @param secure true if the request was received via SSL
* @param clientAddress address that request came from, or null if not-applicable
*/
public HttpInterceptorContext(boolean secure, InetSocketAddress clientAddress) {
Copy link
Contributor

@mikkokar mikkokar Sep 14, 2018

Choose a reason for hiding this comment

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

Please back off this change to the constructor and the static factory method. This PR is now changing 53 files. Majority of them simply because of this unrelated constructor change. Let's keep this PR strictly to removing the client address. This way it is easier to justify and manage the changes, and to review the PRs.

Whether or not it was good idea back in the days to hide the constructor in favour of static factory method is another matter. If you feel strongly about it then please propose that in a separate pull request.

This change will also invalidate any plugins that use HttpInterceptorContext.create in unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added back the method HttpInterceptorContext.create() and reverted tests that use the new constructor.

}

// TODO deprecate
public static HttpInterceptor.Context create() {
Copy link
Contributor

Choose a reason for hiding this comment

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

BTW why are you so keen to deprecate this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The static-factory-method isn't really adding anything. It seems to just be a totally redundant wrapper for the constructor.

Sometimes when we add static-factory-methods to our classes it's to make it read more fluently when statically-imported, but this is just called create so it doesn't have that benefit.

It just changes new HttpInterceptorContext() to HttpInterceptorContext.create() which is actually longer and less convenient.

@@ -159,7 +159,8 @@ class ConditionRouterConfigSpec extends FunSpec with ShouldMatchers with Mockito
|""".stripMargin)

val router = new ConditionRouter.ConfigFactory().build(List(), routeHandlerFactory, config)
val resp = StyxFutures.await(router.handle(request, HttpInterceptorContext.create(false)).asCompletableFuture())

val resp = StyxFutures.await(router.handle(request, new HttpInterceptorContext()).asCompletableFuture())

resp.status() should be(BAD_GATEWAY)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the changes in this file still necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I put back the old HttpInterceptorContext.create() but not HttpInterceptorContext.create(boolean) as I assume we do not want to set a precedent of following that convention (see my reply to your other comment of why I think the create methods are bad).

public HttpInterceptorContext(boolean secure) {
this.secure = secure;
private static InetSocketAddress remoteAddress(ChannelHandlerContext ctx) {
if (ctx.channel() instanceof EmbeddedChannel) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth adding a comment that this is just for unit testing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only moved this method, it's not new.


@Test
public void matchesHttpProtocol() throws Exception {
public void matchesHttpProtocol() {
AntlrMatcher matcher = AntlrMatcher.antlrMatcher("protocol() == 'https'");
Copy link
Contributor

Choose a reason for hiding this comment

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

These changes can also be backed off?


</dependencies>
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change relevant? Looks like it could be backed off?

Let's try to minimise unnecessary changes. Later on if or when we need to consult the Git change log for the relevant changes, perhaps to find out what merge caused a bug, perhaps for another reason, irrelevant or stylistic changes are just a distraction. Therefore they should go into separate pull requests if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved it because I got briefly confused about the module relationships due to the styx-common dependency not being situated near styx-api, and wanting to prevent such confusion in the future. I don't think it merits an entirely separate PR though.

Copy link
Contributor

@mikkokar mikkokar left a comment

Choose a reason for hiding this comment

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

All in all quite good, but I would add few little improvements.

@@ -37,28 +44,42 @@ public RequestEnrichingInterceptor(StyxHeaderConfig styxHeaderConfig) {

@Override
public StyxObservable<HttpResponse> intercept(HttpRequest request, Chain chain) {
return chain.proceed(enrich(request, chain.context().isSecure()));
return chain.proceed(enrich(request, chain));
Copy link
Contributor

Choose a reason for hiding this comment

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

I would pass in the Context only, as enrich doesn't need the full chain.

@kvosper kvosper merged commit 5449484 into ExpediaGroup:master Sep 17, 2018
@kvosper kvosper deleted the removeClientAddress branch September 17, 2018 09:09
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.

2 participants