Pool::create_buffer(n) allocates n bytes, but there is no safe way to put
anything into them:
let mut buf = request.pool().create_buffer(body.len()).unwrap();
buf.as_bytes_mut()[..body.len()].copy_from_slice(body); // panics
ngx_create_temp_buf leaves pos == last, so Buffer::len() is 0 and
MutableBuffer::as_bytes_mut() hands back an empty slice. That is consistent
with as_bytes_mut meaning "the contents", but it leaves the buffer
unfillable: neither trait exposes the capacity or a way to set the length, and
TemporaryBuffer has no inherent methods besides from_ngx_buf. The only
route is as_ngx_buf_mut() and advancing last by hand, which drops out of
the safe API.
create_buffer_from_str works and covers most response bodies, so this is not
urgent. It does mean create_buffer currently has no safe use, while the
obvious composition above compiles and then takes down the worker.
Something like TemporaryBuffer::append(&mut self, &[u8]) -> usize, or
exposing capacity next to a length setter, would close it.
I'd like to work on this issue.
Environment
Pool::create_buffer(n)allocatesnbytes, but there is no safe way to putanything into them:
ngx_create_temp_bufleavespos == last, soBuffer::len()is 0 andMutableBuffer::as_bytes_mut()hands back an empty slice. That is consistentwith
as_bytes_mutmeaning "the contents", but it leaves the bufferunfillable: neither trait exposes the capacity or a way to set the length, and
TemporaryBufferhas no inherent methods besidesfrom_ngx_buf. The onlyroute is
as_ngx_buf_mut()and advancinglastby hand, which drops out ofthe safe API.
create_buffer_from_strworks and covers most response bodies, so this is noturgent. It does mean
create_buffercurrently has no safe use, while theobvious composition above compiles and then takes down the worker.
Something like
TemporaryBuffer::append(&mut self, &[u8]) -> usize, orexposing capacity next to a length setter, would close it.
I'd like to work on this issue.
Environment
ngx0.5.0)