Struct etag::EntityTag [−][src]
pub struct EntityTag { pub weak: bool, // some fields omitted }
An entity tag, defined in RFC7232
The ETag HTTP response header is an identifier for a specific version of a resource. It allows caches to be more efficient, and saves bandwidth, as a web server does not need to send a full response if the content has not changed. On the other side, if the content has changed, etags are useful to help prevent simultaneous updates of a resource from overwriting each other ("mid-air collisions").
If the resource at a given URL changes, a new Etag value must be generated. Etags are therefore similar to fingerprints and might also be used for tracking purposes by some servers. A comparison of them allows to quickly determine whether two representations of a resource are the same, but they might also be set to persist indefinitely by a tracking server.
Format W/"<etag_value>"
-
'W/' (case-sensitive) indicates that a weak validator is used. Weak validators are easy to generate but are far less useful for comparisons. Strong validators are ideal for comparisons but can be very difficult to generate efficiently. Weak Etag values of two representations of the same resources might be semantically equivalent, but not byte-for-byte identical.
-
"<etag_value>" Entity tags uniquely representing the requested resources. They are a string of ASCII characters placed between double quotes (Like "675af34563dc-tr34"). The method by which ETag values are generated is not specified. Oftentimes, a hash of the content, a hash of the last modification timestamp, or just a revision number is used. For example, MDN uses a hash of hexadecimal digits of the wiki content.
Comparison
To check if two entity tags are equivalent in an application always use the
strong_eq
or weak_eq
methods based on the context of the Tag. Only use
==
to check if two tags are identical.
The example below shows the results for a set of entity-tag pairs and both the weak and strong comparison function results:
ETag 1 | ETag 2 | Strong Comparison | Weak Comparison |
---|---|---|---|
W/"1" | W/"1" | no match | match |
W/"1" | W/"2" | no match | no match |
W/"1" | "1" | no match | match |
"1" | "1" | match | match |
Fields
weak: bool
Weakness indicator for the tag
Methods
impl EntityTag
[src]
impl EntityTag
pub fn new(weak: bool, tag: String) -> Self
[src]
pub fn new(weak: bool, tag: String) -> Self
Constructs a new EntityTag.
As tag characters must be in ASCII assert is included to check for it.
pub fn weak(tag: String) -> Self
[src]
pub fn weak(tag: String) -> Self
Constructs a new weak EntityTag.
pub fn strong(tag: String) -> Self
[src]
pub fn strong(tag: String) -> Self
Constructs a new strong EntityTag.
pub fn from_file_meta(metadata: &Metadata) -> Self
[src]
pub fn from_file_meta(metadata: &Metadata) -> Self
Creates weak EntityTag from file metadata using modified time and len.
pub fn from_hash(bytes: &[u8]) -> Self
[src]
pub fn from_hash(bytes: &[u8]) -> Self
Creates strong EntityTag by hashing provided bytes.
pub fn tag(&self) -> &str
[src]
pub fn tag(&self) -> &str
Get the tag.
pub fn set_tag(&mut self, tag: String)
[src]
pub fn set_tag(&mut self, tag: String)
Set the tag.
pub fn strong_eq(&self, other: &EntityTag) -> bool
[src]
pub fn strong_eq(&self, other: &EntityTag) -> bool
For strong comparison two entity-tags are equivalent if both are not weak and their opaque-tags match character-by-character.
pub fn weak_eq(&self, other: &EntityTag) -> bool
[src]
pub fn weak_eq(&self, other: &EntityTag) -> bool
For weak comparison two entity-tags are equivalent if their opaque-tags match character-by-character, regardless of either or both being tagged as "weak".
pub fn strong_ne(&self, other: &EntityTag) -> bool
[src]
pub fn strong_ne(&self, other: &EntityTag) -> bool
The inverse of EntityTag.strong_eq()
.
pub fn weak_ne(&self, other: &EntityTag) -> bool
[src]
pub fn weak_ne(&self, other: &EntityTag) -> bool
The inverse of EntityTag.weak_eq()
.
Trait Implementations
impl Clone for EntityTag
[src]
impl Clone for EntityTag
fn clone(&self) -> EntityTag
[src]
fn clone(&self) -> EntityTag
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for EntityTag
[src]
impl Debug for EntityTag
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Eq for EntityTag
[src]
impl Eq for EntityTag
impl PartialEq for EntityTag
[src]
impl PartialEq for EntityTag
fn eq(&self, other: &EntityTag) -> bool
[src]
fn eq(&self, other: &EntityTag) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &EntityTag) -> bool
[src]
fn ne(&self, other: &EntityTag) -> bool
This method tests for !=
.
impl Display for EntityTag
[src]
impl Display for EntityTag
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl FromStr for EntityTag
[src]
impl FromStr for EntityTag
type Err = ParseError
The associated error which can be returned from parsing.
fn from_str(text: &str) -> Result<EntityTag, ParseError>
[src]
fn from_str(text: &str) -> Result<EntityTag, ParseError>
Parses a string s
to return a value of this type. Read more