Struct soup::MessageHeaders

source ·
pub struct MessageHeaders { /* private fields */ }
Expand description

The HTTP message headers associated with a request or response.

Implementations§

source§

impl MessageHeaders

source

pub fn as_ptr(&self) -> *mut SoupMessageHeaders

Return the inner pointer to the underlying C value.

source

pub unsafe fn from_glib_ptr_borrow<'a>( ptr: *const *const SoupMessageHeaders ) -> &'a Self

Borrows the underlying C value.

source§

impl MessageHeaders

source

pub fn new(type_: MessageHeadersType) -> MessageHeaders

Creates a #SoupMessageHeaders.

(Message does this automatically for its own headers. You would only need to use this method if you are manually parsing or generating message headers.)

§type_

the type of headers

§Returns

a new #SoupMessageHeaders

source

pub fn append(&self, name: &str, value: &str)

Appends a new header with name @name and value @value to @self.

(If there is an existing header with name @name, then this creates a second one, which is only allowed for list-valued headers; see also replace().)

The caller is expected to make sure that @name and @value are syntactically correct.

§name

the header name to add

§value

the new value of @name

source

pub fn clean_connection_headers(&self)

Removes all the headers listed in the Connection header.

source

pub fn clear(&self)

Clears @self.

source

pub fn foreach<P: FnMut(&str, &str)>(&self, func: P)

Calls @func once for each header value in @self.

Beware that unlike list(), this processes the headers in exactly the way they were added, rather than concatenating multiple same-named headers into a single value. (This is intentional; it ensures that if you call append() multiple times with the same name, then the I/O code will output multiple copies of the header when sending the message to the remote implementation, which may be required for interoperability in some cases.)

You may not modify the headers from @func.

§func

callback function to run for each header

source

pub fn content_length(&self) -> i64

Gets the message body length that @self declare.

This will only be non-0 if encoding() returns Encoding::ContentLength.

§Returns

the message body length declared by @self.

source

pub fn content_range(&self) -> Option<(i64, i64, i64)>

Parses @self’s Content-Range header and returns it in @start, @end, and @total_length. If the total length field in the header was specified as “*”, then @total_length will be set to -1.

§Returns

true if @self contained a “Content-Range” header containing a byte range which could be parsed, false otherwise.

§start

return value for the start of the range

§end

return value for the end of the range

§total_length

return value for the total length of the resource, or None if you don’t care.

source

pub fn encoding(&self) -> Encoding

Gets the message body encoding that @self declare.

This may not always correspond to the encoding used on the wire; eg, a HEAD response may declare a Content-Length or Transfer-Encoding, but it will never actually include a body.

§Returns

the encoding declared by @self.

source

pub fn expectations(&self) -> Expectation

Gets the expectations declared by @self’s “Expect” header.

Currently this will either be Expectation::CONTINUE or Expectation::UNRECOGNIZED.

§Returns

the contents of @self’s “Expect” header

source

pub fn headers_type(&self) -> MessageHeadersType

Gets the type of headers.

§Returns

the header’s type.

source

pub fn list(&self, name: &str) -> Option<GString>

Gets the value of header @name in @self.

Use this for headers whose values are comma-delimited lists, and which are therefore allowed to appear multiple times in the headers. For non-list-valued headers, use one().

If @name appears multiple times in @self, list() will concatenate all of the values together, separated by commas. This is sometimes awkward to parse (eg, WWW-Authenticate, Set-Cookie), but you have to be able to deal with it anyway, because the HTTP spec explicitly states that this transformation is allowed, and so an upstream proxy could do the same thing.

§name

header name

§Returns

the header’s value or None if not found.

source

pub fn one(&self, name: &str) -> Option<GString>

Gets the value of header @name in @self.

Use this for headers whose values are not comma-delimited lists, and which therefore can only appear at most once in the headers. For list-valued headers, use list().

If @self does erroneously contain multiple copies of the header, it is not defined which one will be returned. (Ideally, it will return whichever one makes libsoup most compatible with other HTTP implementations.)

§name

header name

§Returns

the header’s value or None if not found.

source

pub fn header_contains(&self, name: &str, token: &str) -> bool

Checks whether the list-valued header @name is present in @self, and contains a case-insensitive match for @token.

(If @name is present in @self, then this is equivalent to calling header_contains() on its value.)

§name

header name

§token

token to look for

§Returns

true if the header is present and contains @token, false otherwise.

source

pub fn header_equals(&self, name: &str, value: &str) -> bool

Checks whether the header @name is present in @self and is (case-insensitively) equal to @value.

§name

header name

§value

expected value

§Returns

true if the header is present and its value is @value, false otherwise.

source

pub fn remove(&self, name: &str)

Removes @name from @self.

If there are multiple values for @name, they are all removed.

§name

the header name to remove

source

pub fn replace(&self, name: &str, value: &str)

Replaces the value of the header @name in @self with @value.

See also append().

The caller is expected to make sure that @name and @value are syntactically correct.

§name

the header name to replace

§value

the new value of @name

source

pub fn set_content_length(&self, content_length: i64)

Sets the message body length that @self will declare, and sets @self’s encoding to Encoding::ContentLength.

You do not normally need to call this; if @self is set to use Content-Length encoding, libsoup will automatically set its Content-Length header for you immediately before sending the headers. One situation in which this method is useful is when generating the response to a HEAD request; Calling set_content_length() allows you to put the correct content length into the response without needing to waste memory by filling in a response body which won’t actually be sent.

§content_length

the message body length

source

pub fn set_content_range(&self, start: i64, end: i64, total_length: i64)

Sets @self’s Content-Range header according to the given values.

(Note that @total_length is the total length of the entire resource that this is a range of, not simply @end - @start + 1.)

Server has built-in handling for range requests, and you do not normally need to call this function youself. See MessageHeaders::get_ranges() for more details.

§start

the start of the range

§end

the end of the range

§total_length

the total length of the resource, or -1 if unknown

source

pub fn set_encoding(&self, encoding: Encoding)

Sets the message body encoding that @self will declare.

In particular, you should use this if you are going to send a request or response in chunked encoding.

§encoding

a #SoupEncoding

source

pub fn set_expectations(&self, expectations: Expectation)

Sets @self’s “Expect” header according to @expectations.

Currently Expectation::CONTINUE is the only known expectation value. You should set this value on a request if you are sending a large message body (eg, via POST or PUT), and want to give the server a chance to reject the request after seeing just the headers (eg, because it will require authentication before allowing you to post, or because you’re POSTing to a URL that doesn’t exist). This saves you from having to transmit the large request body when the server is just going to ignore it anyway.

§expectations

the expectations to set

source

pub fn set_range(&self, start: i64, end: i64)

Sets @self’s Range header to request the indicated range.

@start and @end are interpreted as in a Range.

If you need to request multiple ranges, use MessageHeaders::set_ranges().

§start

the start of the range to request

§end

the end of the range to request

source§

impl MessageHeaders

source

pub fn content_disposition(&self) -> Option<(GString, HashMap<String, String>)>

Looks up the “Content-Disposition” header in @self, parses it, and returns its value in *@disposition and *@params.

@params can be None if you are only interested in the disposition-type.

In HTTP, the most common use of this header is to set a disposition-type of “attachment”, to suggest to the browser that a response should be saved to disk rather than displayed in the browser. If @params contains a “filename” parameter, this is a suggestion of a filename to use. (If the parameter value in the header contains an absolute or relative path, libsoup will truncate it down to just the final path component, so you do not need to test this yourself.)

Content-Disposition is also used in “multipart/form-data”, however this is handled automatically by Multipart and the associated form methods.

§Returns

true if @self contains a “Content-Disposition” header, false if not (in which case *@disposition and *@params will be unchanged).

§disposition

return location for the disposition-type, or None

§params

return location for the Content-Disposition parameters, or None

source

pub fn set_content_disposition( &self, disposition: Option<impl IntoGStr>, params: Option<HashMap<String, String>> )

Sets the “Content-Disposition” header in @self to @disposition, optionally with additional parameters specified in @params.

See content_disposition() for a discussion of how Content-Disposition is used in HTTP.

§disposition

the disposition-type

§params

additional parameters

source

pub fn content_type(&self) -> Option<(GString, HashMap<String, String>)>

Looks up the “Content-Type” header in @self, parses it, and returns its value in *@content_type and *@params.

@params can be None if you are only interested in the content type itself.

§Returns

a string with the value of the “Content-Type” header or None if @self does not contain that header or it cannot be parsed (in which case *@params will be unchanged).

§params

return location for the Content-Type parameters (eg, “charset”), or None

source

pub fn set_content_type( &self, content_type: Option<impl IntoGStr>, params: Option<HashMap<String, String>> )

Sets the “Content-Type” header in @self to @content_type.

Accepts additional parameters specified in @params.

§content_type

the MIME type

§params

additional parameters

Trait Implementations§

source§

impl Clone for MessageHeaders

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for MessageHeaders

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl From<MessageHeaders> for Value

source§

fn from(s: MessageHeaders) -> Self

Converts to this type from the input type.
source§

impl HasParamSpec for MessageHeaders

§

type ParamSpec = ParamSpecBoxed

§

type SetValue = MessageHeaders

Preferred value to be used as setter for the associated ParamSpec.
§

type BuilderFn = fn(_: &str) -> ParamSpecBoxedBuilder<'_, MessageHeaders>

source§

fn param_spec_builder() -> Self::BuilderFn

source§

impl Hash for MessageHeaders

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for MessageHeaders

source§

fn cmp(&self, other: &MessageHeaders) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for MessageHeaders

source§

fn eq(&self, other: &MessageHeaders) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for MessageHeaders

source§

fn partial_cmp(&self, other: &MessageHeaders) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl StaticType for MessageHeaders

source§

fn static_type() -> Type

Returns the type identifier of Self.
source§

impl Eq for MessageHeaders

source§

impl StructuralPartialEq for MessageHeaders

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec(_: *const GList, _: usize) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(_: *const GList, _: usize) -> Vec<T>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GPtrArray, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec( _: *const GPtrArray, _: usize ) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(_: *const GPtrArray, _: usize) -> Vec<T>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *const GSList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(_: *const GSList, _: usize) -> Vec<T>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GList, num: usize) -> Vec<T>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec( ptr: *mut GPtrArray, num: usize ) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GPtrArray, num: usize) -> Vec<T>

source§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

unsafe fn from_glib_none_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_container_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

source§

unsafe fn from_glib_full_num_as_vec(ptr: *mut GSList, num: usize) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *const GList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(_: *const GList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(_: *const GList) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *const GPtrArray) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(_: *const GPtrArray) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(_: *const GPtrArray) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *const GSList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(_: *const GSList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(_: *const GSList) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GList) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GPtrArray) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GPtrArray) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GPtrArray) -> Vec<T>

source§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for T

source§

unsafe fn from_glib_none_as_vec(ptr: *mut GSList) -> Vec<T>

source§

unsafe fn from_glib_container_as_vec(ptr: *mut GSList) -> Vec<T>

source§

unsafe fn from_glib_full_as_vec(ptr: *mut GSList) -> Vec<T>

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoClosureReturnValue for T
where T: Into<Value>,

source§

impl<T> Property for T
where T: HasParamSpec,

§

type Value = T

source§

impl<T> PropertyGet for T
where T: HasParamSpec,

§

type Value = T

source§

fn get<R, F>(&self, f: F) -> R
where F: Fn(&<T as PropertyGet>::Value) -> R,

source§

impl<T> StaticTypeExt for T
where T: StaticType,

source§

fn ensure_type()

Ensures that the type has been registered with the type system.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> TransparentType for T

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T> TryFromClosureReturnValue for T
where T: for<'a> FromValue<'a> + StaticType + 'static,

source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<'a, T, C, E> FromValueOptional<'a> for T
where T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,