Text

User agents

A User-Agent header read: browser, version, system, device kind, and whether it is a crawler.

Version 1.0.0 · 2 functions · 1 crate

#analytics#browsers#bots#devices

Functions

What use useragent.qwer gives a program, with the types Quillo sees. To take only some, or under other names: use parse_user_agent, is_crawler from useragent (Quillo 0.6).

parse_user_agent(ua: str) → any?

{ browser, version, os, os_version, category, vendor } for a User-Agent (category: "pc", "smartphone", "mobilephone", "crawler", "appliance", "misc"), or null when it is unknown.

is_crawler(ua: str) → bool

Whether the User-Agent is a search engine's or another crawler's.

Get it

$ quillo install useragent               # useragent.qwer into this folder$ quillo install useragent --example     # and its example, useragent.qwe

Or with curl:

$ curl -O https://quillolang.org/plugins/files/useragent.qwer$ curl -O https://quillolang.org/plugins/files/useragent.qwe

Then, in your program, all of it or only what you call:

main.qwe
use useragent.qweruse parse_user_agent, is_crawler from useragent      // Quillo 0.6: only these

It uses this crate, which cargo fetches the first time the plugin is built:

[dependencies]
woothee = "0.13"

Example

useragent.qwe
// Who is visiting: browsers and crawlers.////   quillo run useragent.qwe      then open http://localhost:8080/meuse "useragent.qwer"route GET /me = parse_user_agent(request.headers["user-agent"] ?? "")route GET /samples = {    phone: parse_user_agent("Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Mobile/15E148 Safari/604.1"),    bot: is_crawler("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"),}
$ quillo run useragent.qwe$ curl 'localhost:8080/samples'

Source

useragent.qwer
//! What a User-Agent header says: browser, version, system, device kind, and whether it is a crawler.//! version: 1.0.0//!//! [dependencies]//! woothee = "0.13"use serde_json::{json, Value};/// `{ browser, version, os, os_version, category, vendor }` for a User-Agent (category: "pc", "smartphone", "mobilephone", "crawler", "appliance", "misc"), or null when it is unknown.pub fn parse_user_agent(ua: &str) -> Option<Value> {    let r = woothee::parser::Parser::new().parse(ua)?;    Some(json!({        "browser": r.name, "version": r.version, "os": r.os, "os_version": r.os_version.to_string(),        "category": r.category, "vendor": r.vendor,    }))}/// Whether the User-Agent is a search engine's or another crawler's.pub fn is_crawler(ua: &str) -> bool {    woothee::is_crawler(ua)}
Thread
89Useful? Like it, or add to its thread below.

Thread 0 posts

On User agents: questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.