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

Add withUrl(String) #268

Merged
merged 1 commit into from
Sep 5, 2018
Merged

Conversation

htmldoug
Copy link
Contributor

@htmldoug htmldoug commented Jul 31, 2018

Pull Request Checklist

  • Have you read through the contributor guidelines?
  • Have you signed the Typesafe CLA?
  • Have you squashed your commits?
  • Have you added copyright headers to new files?
  • Have you checked that both Scala and Java APIs are updated? (see below)
  • Have you updated the documentation for both Scala and Java sections?
  • Have you added tests for any changed functionality?

Fixes

Fixes #264

Purpose

Adds support in the scala API for changing the url of the WSRequest.

Background Context

Like @gmethvin, I've encountered a couple use cases where I'd like to modify the URL of an existing WSRequest.

  1. Fixing URIs
    In my WSRequestFilters, I'd like to make use of WSRequest.uri, but it's unsafe (see StandaloneWSClient.url(String) permits inconsistent states with query params #267). Today, I have a WSRequestFilter to sanitize the entire request prior to subsequent WSRequestFilters touching WSRequest.uri. In order to strip out query params and any other garbage from the URL, my WSRequestFilter has to rebuild the whole request from scratch. Additionally, it has to require a WSClient to do the job (wsClient.url()), which I hope is the same WSClient that originally used to build the request. Ugh!

  2. Changing hostnames
    We're cursed with https://github.com/mesosphere/marathon-lb, which sometimes fails to route requests. I'd love to be able to have a WSRequestFilter I can use to bypass that layer and rewrite https://pray-marathon-lb-works.example.com/foo to https://10.0.0.25/foo.

@htmldoug
Copy link
Contributor Author

htmldoug commented Jul 31, 2018

I see MiMa failing (correctly for 1.0.0). Is master the right branch for 2.0.0?

[error] (play-ws-standalone / mimaReportBinaryIssues) play-ws-standalone: Binary compatibility check failed!

@htmldoug htmldoug changed the title Add withUrl() Add withUrl(String) Jul 31, 2018
@htmldoug
Copy link
Contributor Author

@gmethvin @marcospereira, you tagged #264 as help wanted. Is this what you had in mind? What are next steps?

@gmethvin
Copy link
Member

I think it looks fine, but we should also update the Java API. It's OK to mutate the variable in the Java API since the API is mutable. Ideally we'd have an immutable API for Java as well but it's probably not worth the breaking change.

@htmldoug
Copy link
Contributor Author

we should also update the Java API. It's OK to mutate the variable in the Java API since the API is mutable.

Thanks, I'll do that today and push to this PR.

@htmldoug
Copy link
Contributor Author

Speaking of breaking changes, adding the withUrl method to the trait counts as a breaking change from MiMa's perspective. (Other implementations may not have implemented it.) Would we merge this with a failing CI build? Any validations I should should be doing locally besides sbt test?

@htmldoug
Copy link
Contributor Author

Java API updated. sbt test passes.

@htmldoug
Copy link
Contributor Author

@gmethvin @marcospereira how's it look now?

@gmethvin
Copy link
Member

I think this can go in the next major release, where we'd allow a breaking change. So you can add a MiMa exclusion, but we just don't want to backport.

@marcospereira
Copy link
Member

LGTM.

We just need to add the mima filters here:

mimaBinaryIssueFilters ++= Seq(

Thanks for helping here, @htmldoug.

@htmldoug
Copy link
Contributor Author

Done. Passing build. Holler if you want me to squash.

@htmldoug
Copy link
Contributor Author

Bump. What's the next step for this PR?

@htmldoug
Copy link
Contributor Author

@marcospereira can we get this in for 2.0.0-M4?

@htmldoug
Copy link
Contributor Author

Freshly squashed per checklist.

@htmldoug htmldoug force-pushed the withUrl branch 2 times, most recently from 7894c84 to 8361d9a Compare August 31, 2018 16:16
@htmldoug
Copy link
Contributor Author

Thanks for the review, @cchantep. Fixed.

@htmldoug
Copy link
Contributor Author

htmldoug commented Sep 4, 2018

Would you like any other changes or can this be merged?

Copy link
Member

@marcospereira marcospereira left a comment

Choose a reason for hiding this comment

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

Two minor changes.

Besides that, LGTM and we can merge after the changes. :-)

Thank you, @htmldoug.

@@ -225,6 +225,12 @@ public StandaloneAhcWSRequest setContentType(String contentType) {
return getHeader(CONTENT_TYPE);
}

@Override
public StandaloneWSRequest setUrl(String url) {
Copy link
Member

Choose a reason for hiding this comment

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

Return StandaloneAhcWSRequest instead.

@@ -183,6 +183,8 @@ case class StandaloneAhcWSRequest(
withMethod(method).execute()
}

override def withUrl(url: String): StandaloneWSRequest = copy(url = url)
Copy link
Member

Choose a reason for hiding this comment

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

Return Self instead.

@htmldoug
Copy link
Contributor Author

htmldoug commented Sep 4, 2018

Done and squashed.

Copy link
Member

@marcospereira marcospereira left a comment

Choose a reason for hiding this comment

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

Thank you, @htmldoug.

And thanks for the patience here too.

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.

5 participants