pub struct UploadBody { /* private fields */ }Expand description
The request body of an upload.
A body has one of two forms:
bytesgives the whole body. The request declares itsContent-Length, and hyper takes the bytes in frames of 64 KiB. A followed redirect sends the bytes again.bytes_with_sha256also gives the SHA-256 of the body to the signer.channelstreams the body. The caller writes the body into theUploadWriterwhile the upload runs. Over HTTP/1.1, the body travels chunked.
If a channel body is dropped before an upload sends it, or after its upload
ends, each write of its writer fails with
io::ErrorKind::BrokenPipe. If the body
of a POST or a PUT is at its end when the fetcher hands over the
request, the request declares a Content-Length of zero.
Implementations§
Source§impl UploadBody
impl UploadBody
Sourcepub fn bytes(bytes: Vec<u8>) -> UploadBody
pub fn bytes(bytes: Vec<u8>) -> UploadBody
Creates a body of bytes.
The request sends the vector in frames cut from it with no copy.
Sourcepub fn bytes_with_sha256(bytes: Vec<u8>, sha256: [u8; 32]) -> UploadBody
pub fn bytes_with_sha256(bytes: Vec<u8>, sha256: [u8; 32]) -> UploadBody
Creates a body of bytes, whose SHA-256 is sha256.
The body is a body of bytes. A signer gets it
as SignPayload::Sha256 with sha256, so a signer that signs the
SHA-256 of the body hashes no byte of it on the task of the request.
Each retry and each redirect hop of the upload uses the same digest,
and so does a copy from try_clone.
The fetcher does not check the digest. A wrong digest signs other bytes than the bytes that the request sends, and the server refuses the request.
Sourcepub fn channel() -> (UploadBody, UploadWriter)
pub fn channel() -> (UploadBody, UploadWriter)
Creates a streamed body and the writer that fills it.
Sourcepub fn as_bytes(&self) -> Option<&[u8]>
pub fn as_bytes(&self) -> Option<&[u8]>
Returns the bytes of a body of bytes, or None
for a streamed body.
Sourcepub fn sha256(&self) -> Option<[u8; 32]>
pub fn sha256(&self) -> Option<[u8; 32]>
Returns the SHA-256 of a body of
bytes_with_sha256, or None for
another body.
Sourcepub fn try_clone(&self) -> Option<UploadBody>
pub fn try_clone(&self) -> Option<UploadBody>
Returns a second body with the same bytes, or None for a streamed
body.
The two bodies of bytes share the one buffer, so
the call copies no byte. The copy keeps the SHA-256 of a body of
bytes_with_sha256. A caller sends
the copy in a second request, for example after the first one failed
with Error::UploadInterrupted. A channel
body has one writer, so it has no copy.
Sourcepub fn into_vec(self) -> Result<Vec<u8>, UploadBody>
pub fn into_vec(self) -> Result<Vec<u8>, UploadBody>
Returns the bytes of a body of bytes as a
vector, or the body unchanged.
If no other body shares the buffer, the call gives the buffer back
with its capacity, and copies no byte. A caller can then fill the
vector again for a later request. The vector does not keep the
SHA-256 of a body of
bytes_with_sha256. A copy from
try_clone shares the buffer, and so does an
upload that still holds the body. The call then returns the body as
the error, as it does for a channel body.
§Errors
Returns the body unchanged if it is a streamed body, or if another body shares its buffer.