pub struct Identity(/* private fields */);Expand description
Who a request appears to come from: a name, an optional proxy, and the headers it sends.
Identities are compared and hashed by name. Cloning is cheap.
Implementations§
Source§impl Identity
impl Identity
Sourcepub fn new(name: impl Into<Box<str>>) -> Self
pub fn new(name: impl Into<Box<str>>) -> Self
Creates an identity named name, with no proxy and no headers.
Sourcepub fn require_no_proxy(&self) -> Result<()>
pub fn require_no_proxy(&self) -> Result<()>
Sourcepub fn with_proxy<U>(self, proxy: U) -> Result<Self>
pub fn with_proxy<U>(self, proxy: U) -> Result<Self>
Sourcepub fn with_header(self, name: impl IntoHeaderName, value: HeaderValue) -> Self
pub fn with_header(self, name: impl IntoHeaderName, value: HeaderValue) -> Self
Sends name with value on every request, unless the request sets
it itself.
Sourcepub fn with_profile(self, profile: Profile) -> Self
Available on crate feature user-agents only.
pub fn with_profile(self, profile: Profile) -> Self
user-agents only.Presents as this browser profile. Identity headers override the profile’s headers, and request headers override both.
Real browser backends refuse profiles: their own browser supplies its user agent and client hints.
Sourcepub fn profile(&self) -> Option<&Profile>
Available on crate feature user-agents only.
pub fn profile(&self) -> Option<&Profile>
user-agents only.Returns the browser profile, kept separate from identity headers.
Sourcepub fn require_no_profile(&self) -> Result<()>
pub fn require_no_profile(&self) -> Result<()>
Sourcepub fn headers(&self) -> &HeaderMap
pub fn headers(&self) -> &HeaderMap
Returns the identity headers, excluding its browser profile.
Sourcepub fn downgrade(&self) -> WeakIdentity
pub fn downgrade(&self) -> WeakIdentity
Returns a weak reference to this identity, which tells whether it is still in use: once the crawl retires it and its last request ends, it is gone. Backends use it to drop what they keep per identity, such as a client or a browser profile.