Skip to content

Instantly share code, notes, and snippets.

@rodrigopr
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodrigopr/d556b6a0f7b7a79b544c to your computer and use it in GitHub Desktop.
Save rodrigopr/d556b6a0f7b7a79b544c to your computer and use it in GitHub Desktop.
import com.twitter.finagle.{Filter, Service}
import com.twitter.finagle.http.{Request ⇒ HttpRequest, Response ⇒ HttpResponse}
import com.twitter.util.Future
import io.finch.{HttpRequest ⇒ HttpxRequest, HttpResponse ⇒ HttpxResponse}
import org.jboss.netty.handler.codec.http.{HttpResponse ⇒ NettyHttpResponse}
/**
* Convert from finagle new `Httpx` to the `Http` representation
*
* This is required to make `httpx` services compatible
* with functionalities that are only available to `Http`
*/
object HttpxToHttpFilter extends Filter[HttpRequest, HttpResponse, HttpxRequest, HttpxResponse] {
override def apply(request: HttpRequest, service: Service[HttpxRequest, HttpxResponse]): Future[HttpResponse] = {
val httpxReq = new HttpxRequest {
val httpRequest = request
lazy val remoteSocketAddress = request.remoteSocketAddress
}
service(httpxReq).map { rep ⇒
new HttpResponse {
val httpResponse: NettyHttpResponse = rep.self.asInstanceOf[NettyHttpResponse]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment