Drew,
> Is there a way to limit the maximum upload size per route? We have multiple API end points with different upload limit sizes. Also, can I customize the response returned when the upload size exceeds the maximum size to be able to return a JSON message?
spray has a clear separation of layers. The low-level spray-can layer is responsible for parsing the incoming HTTP messages and the high-level layers perform whatever high-level logic you define.
The `spray.can.server.parsing.max-content-length` defines what lengths the low-level message parser accepts or doesn’t accept. This parser is the first thing that an incoming request reaches when being received by your server. If the request content-length is too large the request will not be read from the network. Instead an error response is dispatched immediately and the connection closed.
If the content-length is ok the request is read from the network and dispatched to the high-level layer.
As such, by the time a request reaches your route structure it has already been accepted.
Of course you can still handle this request in any way you like in your routes. Treating requests differently depending on their content-length is not problem.
What you have to remember is that incoming requests can also come with `Transfer-Encoding: chunked`, which doesn’t specify a Content-Length.
In this case your application doesn’t know how long the request is going to be. You’ll have to keep track of the length yourself.
What you might find interesting is the `spray.can.server.parsing.incoming-auto-chunking-threshold-size` setting, which allows you to unify all requests to a single (streaming) model.
Sometimes this can help with keeping your high-level logic simpler.
Cheers,
Mathias
---
mat...@spray.io
http://spray.io
> --
> You received this message because you are subscribed to the Google Groups "
spray.io User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
spray-user+...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/spray-user.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/spray-user/B72F65BB-068A-4F82-8D9F-33FB2B92ED6D%40venarc.com.
> For more options, visit
https://groups.google.com/d/optout.