Skip to content

Commit

Permalink
Merge pull request #117 from beenokle/master
Browse files Browse the repository at this point in the history
Use bytes length for content-length instead of string length
  • Loading branch information
twoism committed Feb 18, 2014
2 parents 807859b + 7cc7df8 commit 5615a67
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/com/twitter/finatra/ResponseBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,18 @@ class ResponseBuilder {
view match {
case Some(v) =>
val out = v.render
resp.headers.set("Content-Length", out.length)
resp.setContent(copiedBuffer(out, UTF_8))
val bytes = out.getBytes(UTF_8)
resp.headers.set("Content-Length", bytes.length)
if (v.contentType.isDefined && !resp.headers.contains("Content-Type")) {
resp.headers.set("Content-Type", v.contentType.get)
}
resp.setContent(copiedBuffer(bytes))
case None =>
strBody match {
case Some(sb) =>
resp.headers.set("Content-Length", sb.length)
resp.setContent(copiedBuffer(sb, UTF_8))
val bytes = sb.getBytes(UTF_8)
resp.headers.set("Content-Length", bytes.length)
resp.setContent(copiedBuffer(bytes))
case None =>
binBody match {
case Some(bb) =>
Expand Down

0 comments on commit 5615a67

Please sign in to comment.