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

make client val lazy to allow Client to be extended #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MC-Escherichia
Copy link

@MC-Escherichia MC-Escherichia commented Nov 3, 2017

I recently had a use case where I needed to access a server which had self signed certificates, so I needed to change the underlying Client code in featherbed to use other finagle options. It turns out if you make the instantiation of the val client in the class client lazy, you can do this by extending the class without modifying the Client.scala source. Without the client being lazy, you get initialization errors.

Here was my use case:

package featherbed 

class InsecureClient(
  baseUrl: URL,
  charset: Charset = StandardCharsets.UTF_8)
  extends Client(baseUrl, charset) {

  override protected lazy val client = clientTransform(InsecureClient.forUrl(baseUrl))
}

object InsecureClient {

  private[featherbed] def forUrl(url: URL) = {
    val client = Http.Client()
    if (url.getProtocol == "https") client.withTlsWithoutValidation else client
  }
}

Let me know if more needs to be done.

@codecov-io
Copy link

codecov-io commented Nov 3, 2017

Codecov Report

Merging #73 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #73   +/-   ##
=======================================
  Coverage   67.71%   67.71%           
=======================================
  Files           8        8           
  Lines         254      254           
  Branches        3        2    -1     
=======================================
  Hits          172      172           
  Misses         82       82
Impacted Files Coverage Δ
...herbed-core/src/main/scala/featherbed/Client.scala 92% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1cd0911...26e2498. Read the comment docs.

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