Co-authored-by: Jonas Platte <jplatte@users.noreply.github.com>
Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
Co-authored-by: Rob Ede <robjtede@icloud.com>
* Fix Multipart consuming payload before header checks
What
--
Split up logic in the constructor into two functions:
- **from_boundary:** build Multipart from boundary and stream
- **from_error:** build Multipart for MultipartError
Also we make the `boundary`, `from_boundary`, `from_error` methods public within the crate so that we can use them in the extractor.
The extractor is then able to perform header checks and only consume the
payload if the checks pass.
* Add tests
* Add payload consumption test
Co-authored-by: Rob Ede <robjtede@icloud.com>
* actix-multipart: Fix multipart boundary reading
If we're not ready to read the first line after the multipart field
(which should be a "\r\n" line) then return Pending instead of Ready(None)
so that we will get called again to read that line.
Without this I was getting MultipartError::Boundary from read_boundary()
because it got the "\r\n" line instead of the boundary.
Also tweaks the test_stream test to test partial reads.
This is a forward port of #1189 from 1.0
* actix-multipart: Update changes for boundary fix
* Replace UnsafeCell in DateServiceInner with Cell
The previous API was extremely dangerous - calling `get_ref()`
followed by `reset()` would trigger instant UB, without requiring
any `unsafe` blocks in the caller.
By making DateInner `Copy`, we can use a normal `Cell` instead
of an `UnsafeCell`. This makes it impossible to cause UB (or even panic)
with the API.
* Split unsafe block HttpServiceHandlerResponse
Also add explanation of the safety of the usage of `unsafe`
* Replace UnsafeCell with RefCell in PayloadRef
This ensures that a mistake in the usage of 'get_mut' will cause
a panic, not undefined behavior.