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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ lazy val mimaSettings = mimaDefaultSettings ++ Seq(
ProblemFilters.exclude[ReversedMissingMethodProblem]("play.libs.ws.StandaloneWSRequest.getMethod"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("play.libs.ws.StandaloneWSRequest.setAuth"),

// Added in #268 for 2.0.0
ProblemFilters.exclude[ReversedMissingMethodProblem]("play.libs.ws.StandaloneWSRequest.setUrl"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("play.api.libs.ws.StandaloneWSRequest.withUrl"),

// Now have a default implementation at the interface
ProblemFilters.exclude[DirectMissingMethodProblem]("play.libs.ws.ahc.StandaloneAhcWSRequest.getPassword"),
ProblemFilters.exclude[DirectMissingMethodProblem]("play.libs.ws.ahc.StandaloneAhcWSRequest.getUsername"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class StandaloneAhcWSRequest implements StandaloneWSRequest {

private BodyWritable<?> bodyWritable;

private final String url;
private String url;
private String method = "GET";
private final Map<String, List<String>> headers = new HashMap<>();
private final Map<String, List<String>> queryParameters = new LinkedHashMap<>();
Expand Down Expand Up @@ -225,6 +225,12 @@ public Optional<String> getContentType() {
return getHeader(CONTENT_TYPE);
}

@Override
public StandaloneAhcWSRequest setUrl(String url) {
this.url = url;
return this;
}

@Override
public StandaloneAhcWSRequest setMethod(String method) {
this.method = method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ case class StandaloneAhcWSRequest(
withMethod(method).execute()
}

override def withUrl(url: String): Self = copy(url = url)

override def withMethod(method: String): Self = copy(method = method)

override def execute(): Future[Response] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,12 @@ class AhcWSRequestSpec extends Specification with Mockito with AfterAll with Def

"StandaloneAhcWSRequest supports" in {

"replace url" in withClient { client =>
val req = client.url("http://playframework.com/")
.withUrl("http://www.example.com/")
req.url must_=== "http://www.example.com/"
}

"a custom signature calculator" in {
var called = false
val calc = new play.shaded.ahc.org.asynchttpclient.SignatureCalculator with WSSignatureCalculator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,25 @@ class AhcWSRequestSpec extends Specification with Mockito with DefaultBodyReadab
actual must beEqualTo("foo.com")
}

"set the url" in {
val client = mock[StandaloneAhcWSClient]
val req = new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
req.getUrl must be_===("http://playframework.com/") and {
val setReq = req.setUrl("http://example.com")
setReq.getUrl must be_===("http://example.com") and {
setReq must be_===(req)
}
}
}

"For POST requests" in {

"get method" in {
val client = mock[StandaloneAhcWSClient]
val req = new StandaloneAhcWSRequest(client, "http://playframework.com/", null)
.setMethod("POST")

req.getMethod must be_==("POST")
req.getMethod must be_===("POST")
}

"set text/plain content-types for text bodies" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ public interface StandaloneWSRequest {
// Setters
//-------------------------------------------------------------------------

/**
* Sets the URL of the request.
*
* @param url the URL of the request
* @return the modified WSRequest.
*/
StandaloneWSRequest setUrl(String url);

/**
* Sets the HTTP method this request should use, where the no args execute() method is invoked.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ trait StandaloneWSRequest {
*/
def withProxyServer(proxyServer: WSProxyServer): Self

/**
* Sets the url for this request.
*/
def withUrl(url: String): Self

/**
* Sets the method for this request
*/
Expand Down