Skip to content

Commit

Permalink
Adds another less intrusive render pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
casualjim committed Apr 1, 2011
1 parent 4c77811 commit 5399127
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions core/src/main/scala/org/scalatra/ScalatraKernel.scala
Expand Up @@ -186,16 +186,20 @@ trait ScalatraKernel extends Handler with Initializable
(contentTypeInfer orElse defaultContentTypeInfer).apply(actionResult)

protected def renderResponseBody(actionResult: Any) {
actionResult match {
case bytes: Array[Byte] =>
response.getOutputStream.write(bytes)
case file: File =>
using(new FileInputStream(file)) { in => zeroCopy(in, response.getOutputStream) }
case _: Unit =>
// If an action returns Unit, it assumes responsibility for the response
case x: Any =>
response.getWriter.print(x.toString)
}
(renderPipeline orElse defaultRenderResponse) apply actionResult
}

protected def renderPipeline: PartialFunction[Any, Any] = defaultRenderResponse

protected final def defaultRenderResponse: PartialFunction[Any, Any] = {
case bytes: Array[Byte] =>
response.getOutputStream.write(bytes)
case file: File =>
using(new FileInputStream(file)) { in => zeroCopy(in, response.getOutputStream) }
case _: Unit =>
// If an action returns Unit, it assumes responsibility for the response
case x: Any =>
response.getWriter.print(x.toString)
}

protected[scalatra] val _multiParams = new DynamicVariable[MultiMap](new MultiMap)
Expand Down

0 comments on commit 5399127

Please sign in to comment.