Struct soup::MessageBody
source · pub struct MessageBody { /* private fields */ }
Expand description
#SoupMessageBody represents the request or response body of a
Message
.
Note that while @length always reflects the full length of the
message body, @data is normally None
, and will only be filled in
after flatten()
is called. For client-side
messages, this automatically happens for the response body after it
has been fully read. Likewise, for server-side
messages, the request body is automatically filled in after being
read.
As an added bonus, when @data is filled in, it is always terminated
with a \0
byte (which is not reflected in @length).
Implementations§
source§impl MessageBody
impl MessageBody
source§impl MessageBody
impl MessageBody
sourcepub fn new() -> MessageBody
pub fn new() -> MessageBody
sourcepub fn append_bytes(&self, buffer: &Bytes)
pub fn append_bytes(&self, buffer: &Bytes)
sourcepub fn append_take(&self, data: &[u8])
pub fn append_take(&self, data: &[u8])
Appends @length bytes from @data to @self.
This function is exactly equivalent to MessageBody::append()
with MemoryUse::Take
as second argument; it exists mainly for
convenience and simplifying language bindings.
§data
data to append
sourcepub fn complete(&self)
pub fn complete(&self)
Tags @self as being complete.
Call this when using chunked encoding after you have appended the last chunk.
sourcepub fn flatten(&self) -> Option<Bytes>
pub fn flatten(&self) -> Option<Bytes>
Fills in @self’s data field with a buffer containing all of the data in @self.
Adds an additional \0
byte not counted by @self’s
length field.
§Returns
a #GBytes containing the same data as @self.
(You must GLib::Bytes::unref()
this if you do not want it.)
sourcepub fn is_accumulate(&self) -> bool
pub fn is_accumulate(&self) -> bool
Gets the accumulate flag on @self.
See set_accumulate()
. for details.
§Returns
the accumulate flag for @self.
sourcepub fn chunk(&self, offset: i64) -> Option<Bytes>
pub fn chunk(&self, offset: i64) -> Option<Bytes>
Gets a glib::Bytes
containing data from @self starting at @offset.
The size of the returned chunk is unspecified. You can iterate
through the entire body by first calling
chunk()
with an offset of 0, and then on each
successive call, increment the offset by the length of the
previously-returned chunk.
If @offset is greater than or equal to the total length of @self,
then the return value depends on whether or not
complete()
has been called or not; if it has,
then chunk()
will return a 0-length chunk
(indicating the end of @self). If it has not, then
chunk()
will return None
(indicating that
@self may still potentially have more data, but that data is not
currently available).
§offset
an offset
§Returns
a #GBytes
sourcepub fn got_chunk(&self, chunk: &Bytes)
pub fn got_chunk(&self, chunk: &Bytes)
Handles the #SoupMessageBody part of receiving a chunk of data from the network.
Normally this means appending @chunk to @self, exactly as with
append_bytes()
, but if you have set @self’s accumulate
flag to false
, then that will not happen.
This is a low-level method which you should not normally need to use.
§chunk
a #GBytes received from the network
sourcepub fn set_accumulate(&self, accumulate: bool)
pub fn set_accumulate(&self, accumulate: bool)
Sets or clears the accumulate flag on @self.
(The default value is true
.) If set to false
, @self’s data field will not
be filled in after the body is fully sent/received, and the chunks that make
up @self may be discarded when they are no longer needed.
If you set the flag to false
on the Message
request_body of a
client-side message, it will block the accumulation of chunks into
@self’s data field, but it will not normally cause the chunks to
be discarded after being written like in the server-side
Message
response_body case, because the request body needs to
be kept around in case the request needs to be sent a second time
due to redirection or authentication.
§accumulate
whether or not to accumulate body chunks in @self
sourcepub fn wrote_chunk(&self, chunk: &Bytes)
pub fn wrote_chunk(&self, chunk: &Bytes)
Handles the #SoupMessageBody part of writing a chunk of data to the network.
Normally this is a no-op, but if you have set @self’s accumulate flag to
false
, then this will cause @chunk to be discarded to free up memory.
This is a low-level method which you should not need to use, and there are further restrictions on its proper use which are not documented here.
§chunk
a #GBytes returned from chunk()
Trait Implementations§
source§impl Clone for MessageBody
impl Clone for MessageBody
source§impl Debug for MessageBody
impl Debug for MessageBody
source§impl Default for MessageBody
impl Default for MessageBody
source§impl From<MessageBody> for Value
impl From<MessageBody> for Value
source§fn from(s: MessageBody) -> Self
fn from(s: MessageBody) -> Self
source§impl HasParamSpec for MessageBody
impl HasParamSpec for MessageBody
type ParamSpec = ParamSpecBoxed
§type SetValue = MessageBody
type SetValue = MessageBody
type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, MessageBody>
fn param_spec_builder() -> Self::BuilderFn
source§impl Hash for MessageBody
impl Hash for MessageBody
source§impl Ord for MessageBody
impl Ord for MessageBody
source§fn cmp(&self, other: &MessageBody) -> Ordering
fn cmp(&self, other: &MessageBody) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for MessageBody
impl PartialEq for MessageBody
source§fn eq(&self, other: &MessageBody) -> bool
fn eq(&self, other: &MessageBody) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for MessageBody
impl PartialOrd for MessageBody
source§fn partial_cmp(&self, other: &MessageBody) -> Option<Ordering>
fn partial_cmp(&self, other: &MessageBody) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl StaticType for MessageBody
impl StaticType for MessageBody
source§fn static_type() -> Type
fn static_type() -> Type
Self
.