Skip to content

Commit

Permalink
Add withUrl()
Browse files Browse the repository at this point in the history
  • Loading branch information
htmldoug committed Aug 31, 2018
1 parent 925c287 commit e41336d
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 1 deletion.
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 StandaloneWSRequest 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): StandaloneWSRequest = 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 be equalTo "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,6 +36,16 @@ 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/")

val setReq = req.setUrl("http://example.com")
setReq.getUrl must be_===("http://example.com")
setReq must be_===(req)
}

"For POST requests" in {

"get method" 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

0 comments on commit e41336d

Please sign in to comment.