pub struct Cookie { /* private fields */ }
Expand description
Option data for a DNS cookie.
A value of this type carries two parts: A mandatory ClientCookie
and
an optional ServerCookie
. The client cookie is chosen by, yes, the
client and added to a request when contacting a specific server for the
first time. When responding, a server calculates a server cookie from the
client cookie and adds both of them to the response. The client remembers
both and includes them in subsequent requests. The server can now check
that the the server cookie was indeed calculated by it and treat the
repeat customer differently.
While you can create a new cookie using the new
method,
shortcuts are available for the standard workflow. A new initial cookie
can be created via create_initial
. As this will
be a random client cookie, it needs the rand
feature. The server can
check whether a received cookie includes a server cookie created by it
via the [check_server_hash
][Self::check_server_hash] method. It needs
the SipHash-2-4 algorithm and is thus available if the siphasher
feature
is enabled. The same feature also enables the
[create_response
][Self::create_response] method which creates the server
cookie to be included in a response.
Implementations§
source§impl Cookie
impl Cookie
sourcepub fn new(client: ClientCookie, server: Option<ServerCookie>) -> Self
pub fn new(client: ClientCookie, server: Option<ServerCookie>) -> Self
Creates a new cookie from client and optional server cookie.
sourcepub fn client(&self) -> ClientCookie
pub fn client(&self) -> ClientCookie
Returns the client cookie.
sourcepub fn server(&self) -> Option<&ServerCookie>
pub fn server(&self) -> Option<&ServerCookie>
Returns a reference to the server cookie if present.
sourcepub fn parse<Octs: AsRef<[u8]> + ?Sized>(
parser: &mut Parser<'_, Octs>,
) -> Result<Self, ParseError>
pub fn parse<Octs: AsRef<[u8]> + ?Sized>( parser: &mut Parser<'_, Octs>, ) -> Result<Self, ParseError>
Parses the cookie from its wire format.
sourcepub fn create_initial() -> Self
pub fn create_initial() -> Self
Creates a random client cookie for including in an initial request.
Trait Implementations§
source§impl ComposeOptData for Cookie
impl ComposeOptData for Cookie
fn compose_len(&self) -> u16
fn compose_option<Target: OctetsBuilder + ?Sized>( &self, target: &mut Target, ) -> Result<(), Target::AppendError>
source§impl<Octs, Name> From<Cookie> for AllOptData<Octs, Name>
impl<Octs, Name> From<Cookie> for AllOptData<Octs, Name>
source§impl OptData for Cookie
impl OptData for Cookie
source§fn code(&self) -> OptionCode
fn code(&self) -> OptionCode
source§impl Ord for Cookie
impl Ord for Cookie
source§impl<'a, Octs: AsRef<[u8]> + ?Sized> ParseOptData<'a, Octs> for Cookie
impl<'a, Octs: AsRef<[u8]> + ?Sized> ParseOptData<'a, Octs> for Cookie
source§fn parse_option(
code: OptionCode,
parser: &mut Parser<'a, Octs>,
) -> Result<Option<Self>, ParseError>
fn parse_option( code: OptionCode, parser: &mut Parser<'a, Octs>, ) -> Result<Option<Self>, ParseError>
source§impl PartialEq for Cookie
impl PartialEq for Cookie
source§impl PartialOrd for Cookie
impl PartialOrd for Cookie
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 more