1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! User-agent detection: the operating system, client, device and bot
//! behind a user-agent string.
//!
//! Any bytes are accepted, including bytes that are not UTF-8, and what is
//! read from the string is borrowed from it.
//!
//! ```
//! use utopia_user_agent::UserAgent;
//!
//! let agent = UserAgent::parse("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0");
//! assert_eq!(agent.operating_system().version.as_deref(), Some(b"7".as_slice()));
//! assert_eq!(agent.client().name.as_deref(), Some(b"Firefox".as_slice()));
//! assert!(!agent.is_bot());
//! ```
//!
//! Detection runs on every request, so it avoids regular expressions where
//! native code does the same job: case-insensitive substring, word and
//! `<token>/<version>` scans that never allocate, and one pass over the
//! string for the whole bot table. The few patterns left (device models
//! and brands, Internet Explorer, the generic bot rule) are compiled once
//! per process, and run only when the string holds a literal they need.
//!
//! PHP: the port of `utopia-php/user-agent` (`packages/user-agent`), with
//! identical results for every input. The remaining patterns are the PHP
//! library's, run by [`php_std::pcre`] (a port of the PCRE2 PHP uses); each
//! native scan names the pattern it replaces, and the crate's tests check
//! every one, and every prefilter, against that pattern.
//!
//! | PHP | Rust |
//! |---|---|
//! | `UserAgent::parse($value)` | [`UserAgent::parse`] |
//! | `UserAgent::raw()` | [`UserAgent::raw`] |
//! | `UserAgent::operatingSystem()` / `client()` / `device()` / `bot()` | [`UserAgent::operating_system`], [`UserAgent::client`], [`UserAgent::device`], [`UserAgent::bot`] |
//! | `UserAgent::isBot()` | [`UserAgent::is_bot`] |
//! | `UserAgent::toArray()`, `*::toArray()` | the public fields of [`OperatingSystem`], [`Client`], [`Device`], [`Bot`] |
//! | `OperatingSystem` (`code`, `name`, `version`, `isKnown()`) | [`OperatingSystem`], [`OperatingSystem::is_known`] |
//! | `Client` (`type`, ..., `engineVersion`, `isKnown()`, `isBrowser()`) | [`Client`] (`kind`, ..., `engine_version`), [`Client::is_known`], [`Client::is_browser`] |
//! | `Device` (`type`, `brand`, `model`, `isKnown()`) | [`Device`] (`kind`, ...), [`Device::is_known`] |
//! | `new Bot($name, $category = 'crawler')` | [`Bot::new`], [`Bot::with_category`] |
//! | `Detection\OperatingSystemDetector::detect()` | [`detection::operating_system`] |
//! | `Detection\ClientDetector::detect()` | [`detection::client`] |
//! | `Detection\DeviceDetector::detect()` | [`detection::device`] |
//! | `Detection\BotDetector::detect()` | [`detection::bot`] |
//!
//! PHP: Appwrite's session attributes (`Appwrite\Detector\Detector`) are in
//! `appwrite_core::detector`.
pub use UserAgent;
pub use ;
/// The getting started guide (`guide.md`), compiled and run with the doctests.
;