#Mist / Http body lost sometime
1 messages · Page 1 of 1 (latest)
are you explicitly reading the body with mist.read_body? https://hexdocs.pm/mist/mist.html#read_body (or https://hexdocs.pm/mist/mist.html#read_request_body if you don't want to manually call it on every request)
Thanks a lot, it's much better now
OLD:
case req.body.body {
Initial(data) -> {
case bit_array.to_string(data) {
Ok(data_str) -> {
case data_str {
"" -> content_not_valid
_ -> {
// process...
}
}
}
_ -> content_not_valid
}
}
}
NEW:
case mist.read_body(req, 4_000_000) {
Ok(data) -> {
case bit_array.to_string(data.body) {
Ok(data_str) -> {
case data_str {
"" -> content_not_valid
_ -> {
// process...
}
}
}
_ -> content_not_valid
}
}
_ -> content_not_valid
}
}
i should probably make it so you can't do that... so accessing the body like that is definitely not guaranteed to have any/all of the actual body of the request
i edited my message, i pressed enter before finishing my message, it's my fault.
yes, you can access it directly in my old way, but there's no guarantee that you'll get the body content
but on the other hand, it's a bit odd to have to call the read_body function to get the real body content, because in python you can access it directly with response.content or request.body (I've just checked, it's a property function behind it https://github.com/psf/requests/blob/f1bb07d39b74d6444e333879f8b8a3d9dd4d2311/src/requests/models.py#L886)
So we can call read_body when gleam performs its process before the user's process, and so when the user accesses .body, it gets the actual body contents ?
btw the Wisp library will handle lots of tricky stuff around reading bodies etc, may be nicer for applications than using Mist directly.
yes i saw that when i was looking for a module before starting, but my current project is not an application, it's just a tiny api where i need performance, so mist seems to be the best option for the project, with the carpenter module too, so that way i stay with rawhat's work, congrats by the way.
haha thanks! the overhead of wisp is negligible if anything, so i would personally say unless you need websockets go for that
but yeah, we don't have the luxury of mutating properties, and also i wanted it to be flexible like... maybe you want to reject requests with large payloads or something. in which case, i didn't want to eagerly drop it into your handler
Wisp won’t add any runtime cost, nah