pub enum Browser {
Chrome,
Edge,
Firefox,
InternetExplorer,
Opera,
Safari,
}Expand description
A browser family that AllowBrowser recognizes in the User-Agent header.
§Examples
use ocre::security::Browser;
let ua = "Mozilla/5.0 (Macintosh; Intel Mac OS X 14_4) AppleWebKit/605.1.15 (KHTML, like Gecko) \
Version/17.4 Safari/605.1.15";
assert_eq!(Browser::detect(ua), Some((Browser::Safari, (17, 4))));
assert_eq!(Browser::detect("curl/8.7.1"), None);Variants§
Chrome
Google Chrome and Chromium (Chrome/, CriOS/ on iOS).
Edge
Microsoft Edge (Edg/, EdgA/, EdgiOS/).
Firefox
Mozilla Firefox (Firefox/).
InternetExplorer
Internet Explorer (MSIE, Trident/).
Opera
Opera (OPR/).
Safari
Apple Safari (Version/... Safari/).
Implementations§
Source§impl Browser
impl Browser
Sourcepub fn detect(user_agent: &str) -> Option<(Browser, (u32, u32))>
pub fn detect(user_agent: &str) -> Option<(Browser, (u32, u32))>
The browser and its (major, minor) version named by a User-Agent, or None for anything else (bots, curl).
Tokens are checked from the most specific: Edge and Opera also send
Chrome/, and Chrome also sends Safari/. Pure CPU.
§Examples
use ocre::security::Browser;
let edge = "Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 \
Safari/537.36 Edg/124.0.2478.51";
assert_eq!(Browser::detect(edge), Some((Browser::Edge, (124, 0))));
assert_eq!(Browser::detect("Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)"),
Some((Browser::InternetExplorer, (8, 0))));Trait Implementations§
impl Copy for Browser
impl Eq for Browser
impl StructuralPartialEq for Browser
Auto Trait Implementations§
impl Freeze for Browser
impl RefUnwindSafe for Browser
impl Send for Browser
impl Sync for Browser
impl Unpin for Browser
impl UnsafeUnpin for Browser
impl UnwindSafe for Browser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.