Set limit on response size for as_str handler

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Set limit on response size for as_str handler

parsa
Hi folks,

I'm willing to use Dispatch in a sandboxed environment, where among all limitations, I need to set a limit on how large the response string can be. How can this be achieved in Dispatch? Thanks in advance.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set limit on response size for as_str handler

n8han
Administrator
On 07/16/2011 02:56 AM, parsa [via Databinder] wrote:
> I'm willing to use Dispatch in a sandboxed environment, where among
> all limitations, I need to set a limit on how large the response
> string can be. How can this be achieved in Dispatch? Thanks in advance.

Sure, you can consume the stream/reader/scala.io.Source to build up a
stream of whatever maximum size you want. The String methods are just
doing this:

     request >~ { so => so.mkString }

Where so is a scala.io.Source. Source works line by line so if you are
concerned about very long lines you may want to work with lower level
java stream or reader. For reader,

     request >>~ { reader => [make as big of a string as you want here] }

and that value will be returned. Sources here:

https://github.com/n8han/Databinder-Dispatch/blob/master/core/src/main/scala/handlers.scala#L88

Nathan
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Set limit on response size for as_str handler

parsa
tyvm Nathan :)
Loading...