Skip to content

Instantly share code, notes, and snippets.

@nisshiee
Last active February 25, 2016 13:12
Show Gist options
  • Save nisshiee/6414370 to your computer and use it in GitHub Desktop.
Save nisshiee/6414370 to your computer and use it in GitHub Desktop.
Dispatchの文字化け対策
import dispatch._
import com.ning.http.client.filter.{ ResponseFilter, FilterContext }
import scala.collection.JavaConverters._
val MyHttp = Http.configure { builder =>
builder.addResponseFilter(new ResponseFilter {
override def filter(ctx: FilterContext[_]) = {
ctx.getResponseHeaders.getHeaders.get("Content-Type").asScala.toList match {
case "text/html" :: Nil =>
ctx.getResponseHeaders.getHeaders.put("Content-Type", List("text/html; charset=utf-8").asJava)
case _ => ()
}
ctx
}
})
}
MyHttp(url("http://example.com") OK as.String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment