This example use both a Server and a Client to create an HTTP reverse proxy.

import lol.http._ import  

Let's proxy 😼.

object ReverseProxy { def main(args: Array[String]): Unit = {  

We need an HTTP client connected to The connection is done in HTTPS, so we need to specify the port and scheme.

val wikipediaClient = Client("", 443, "https")  

Now we start an HTTP server.

Server.listen(8888) {  

If the request is a GET /, we redirect the browser to teh Criteo page. That's the only feature of our reverse proxy!

case GET at url"/" => Redirect("/wiki/Criteo")  

In any other case, we pass the request to the client we just created, so it is sent to wikipedia, and the response is written back to the browser.

case request => wikipediaClient

We need to change the Host header, so the wikipedia server will accept the request.

request.addHeaders(Headers.Host -> h"") } } println("Proxying wikipedia on http://localhost:8888...") } }