Created
July 9, 2017 03:21
-
-
Save isterin/c920a488f9beaf5f31858aaa6eb52a58 to your computer and use it in GitHub Desktop.
Scala automatic wrapper/delegation with implicits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxiedHttpRequest(val req:HttpRequest) { | |
lazy val proxyServer = InetAddress.getByName(“some.proxy.com”) | |
} | |
object ProxiedHttpRequest { | |
implicit def delegateToOriginalHttpRequest( | |
r: ProxiedHttpRequest):HttpRequest = r.req | |
} | |
object Application { | |
def proxyRequest(req:ProxiedHttpRequest) { | |
val where = req.proxyServer | |
val headers = req.headers() // No more req.req ugliness | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProxiedHttpRequest(val req:HttpRequest) { | |
lazy val proxyServer = InetAddress.getByName(“some.proxy.com”) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def proxyRequest(req:ProxiedHttpRequest) { | |
val where = req.proxyServer | |
/* | |
Here I need access to original request being wrapped to get the headers This is ugly and I’d prefer to access it as I would a regular HttpRequest req.headers() | |
*/ | |
val headers = req.req.headers() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment