Last active
September 26, 2015 12:14
-
-
Save halcat0x15a/99d2370f47d8b14eedb6 to your computer and use it in GitHub Desktop.
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
import com.twitter.finagle.{Http, Service} | |
import com.twitter.util.{Await, Future} | |
import java.net.URI | |
import org.jboss.netty.handler.codec.http._ | |
object Proxy extends App { | |
val service = new Service[HttpRequest, HttpResponse] { | |
def apply(req: HttpRequest): Future[HttpResponse] = { | |
val client = Http.newService(s"${new URI(req.getUri).getAuthority}:80") | |
val res = client(req) | |
res onSuccess { res => | |
val buf = res.getContent | |
val data = new Array[Byte](buf.capacity) | |
buf.getBytes(0, data) | |
println(new String(data, "UTF-8")) | |
} | |
} | |
} | |
val server = Http.serve(":8080", service) | |
Await.ready(server) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment