Skip to content

Commit

Permalink
Merge pull request #480 from mkurz/https_improvements
Browse files Browse the repository at this point in the history
[6.0.x] https improvements
  • Loading branch information
mkurz authored Dec 21, 2023
2 parents 9033082 + 6322678 commit 1bd4cc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ trait ServerProvider {
* @return the configured port number, wrapped in a `PortNumber`
*/
implicit def portNumber: PortNumber = {
val httpEndpoint = runningServer.endpoints.httpEndpoint
val port = httpEndpoint
.fold(throw new IllegalStateException("No HTTP port available for test server"))(_.port)
val port = runningServer.endpoints.httpEndpoint
.orElse(runningServer.endpoints.httpsEndpoint)
.fold(throw new IllegalStateException("Nor HTTP or HTTPS port available for test server"))(_.port)
PortNumber(port)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ trait WsScalaTestClient {
def wsUrl(url: String)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest =
doCall(url, wsClient, portNumber)

private def doCall(url: String, wsClient: WSClient, portNumber: PortNumber) = {
wsClient.url("http://localhost:" + portNumber.value + url)
/**
* Construct a WS request for the given relative URL.
*
* @param url the URL of the request
* @param secure if the request should be send via https
* @param portNumber the port number of the `TestServer`
* @param wsClient the implicit WSClient
*/
def wsUrl(url: String, secure: Boolean)(implicit portNumber: PortNumber, wsClient: WSClient): WSRequest =
doCall(url, wsClient, portNumber, secure)

private def doCall(url: String, wsClient: WSClient, portNumber: PortNumber, secure: Boolean = false) = {
wsClient.url((if (secure) "https" else "http") + "://localhost:" + portNumber.value + url)
}
}

0 comments on commit 1bd4cc8

Please sign in to comment.