Skip to content

Instantly share code, notes, and snippets.

@halcat0x15a
Last active September 26, 2015 12:14
Show Gist options
  • Save halcat0x15a/99d2370f47d8b14eedb6 to your computer and use it in GitHub Desktop.
Save halcat0x15a/99d2370f47d8b14eedb6 to your computer and use it in GitHub Desktop.
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