https://kotlinlang.org logo
#http4k
Title
# http4k
t

tryge

12/11/2018, 1:03 PM
Hi everyone, is there a way to stream body payload on the server side, or at least restrict its size to a same limit without reading it into memory?
d

dave

12/11/2018, 1:20 PM
is this from the serverside or from the clientside?
t

tryge

12/11/2018, 1:20 PM
server side, we want to protect the server from filling memory
d

dave

12/11/2018, 1:21 PM
ok - which server are you using?
t

tryge

12/11/2018, 1:21 PM
at the moment just
SunHttp
is this server dependent?
we’ll deploy to AWS Lambda
d

dave

12/11/2018, 1:22 PM
well not really - but you can, for instance, configure undertow to only accept a certain size of request.
t

tryge

12/11/2018, 1:22 PM
can it be done in http4k as well, or do we need to configure it on the server?
d

dave

12/11/2018, 1:23 PM
anyway, you can get the stream from incoming request
request.body.stream
t

tryge

12/11/2018, 1:24 PM
We saw it’s already closed when we try to access it in the handler. Is there a size limit of when the request won’t be read immediately?
Thank you for your time!
d

dave

12/11/2018, 1:25 PM
np 🙂
SunHttp definitely does support request streaming. We've even got a test to prove it..
SunHttpStreamingTest
t

tryge

12/11/2018, 1:25 PM
ok great, thank you very much!
I’ll look into the test 🙂
d

dave

12/11/2018, 1:26 PM
one danger is that you may be accessing the payload before attempting to read the stream.
doing that WILL pull the contents of the stream into memory -
this often happens when you debug the input using a filter
(we've been caught by it several times!)
t

tryge

12/11/2018, 2:03 PM
yes, it was the debugger !
we moved the breakpoint and it started working 🙂
thank you again
d

dave

12/11/2018, 3:37 PM
😂
3 Views