SHARYA...:Simple(3pm)

πŸ“¦
version 0.77 Β· 2 versions
  • 0.77 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.77 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

SHARYANTO::HTTP::DetectUA::Simple β€” a very simple and generic browser detection library πŸ’… lowkey does exactly what it says on the tin, no cap.


🌸 VERSION 🌸

This doc describes version 0.77 of SHARYANTO::HTTP::DetectUA::Simple β€” which ships in the Perl distribution SHARYANTO-Utils β€” and it dropped on 2015-09-04. πŸŽ€


🫢 SEE ALSO 🫢

  • SHARYANTO

πŸ¦‹ HOMEPAGE πŸ¦‹

Bestie, go visit the project's homepage at <https://metacpan.org/release/SHARYANTO-Utils>. It's giving home. 🏠✨


🌈 SOURCE 🌈

The source repository lives at <https://github.com/perlancar/perl-SHARYANTO-Utils>. Go be nosy, it's fine. πŸ‘€


πŸ’€ BUGS πŸ’€

Found a bug? Want a feature? Please report it on the bugtracker website <https://rt.cpan.org/Public/Dist/Display.html?Name=SHARYANTO-Utils>. πŸ™ˆ

When you submit a bug or a request, please include a test-file, or a patch to an existing test-file, that illustrates the bug or the desired feature. Not me asking for the whole backstory with zero receipts β€” give us the test file bestie. 😭

πŸ‘‘ AUTHOR πŸ‘‘

perlancar <perlancar@cpan.org>


This software is copyright (c) 2015 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Periodt. πŸŽ€


✨ DESCRIPTION ✨

Okay so real talk: I needed a simple and fast routine that can detect whether an HTTP client is a GUI browser (like Chrome or Firefox), a text browser (like Lynx or Links), or neither (like curl, or LWP). Hence, this module. That's it, that's the origin story. 🧚


πŸŽ€ FUNCTIONS πŸŽ€

πŸ’… detect_http_ua_simple($env) -> [status, msg, result, meta]

Detect whether the HTTP client is a GUI/TUI browser. Vibe check, but for user agents. πŸ”₯

This function is a simple and fast routine to detect whether an HTTP client is a GUI browser (like Chrome or Firefox), a text-based browser (like Lynx or Links), or neither (like curl or LWP). Extra information can be provided in the future β€” slay, future-proofing. ✨

Currently these heuristic rules are used:

  • check popular browser markers in the User-Agent header (e.g. 'Chrome', 'Opera');
  • check the Accept header for 'image/'.

It is several times faster than the other equivalent Perl modules, and that's because it does significantly less. Main character energy: does the one thing, does it fast, leaves. πŸ‘‘

Arguments ('*' denotes required arguments):

  • env => any

CGI-compatible environment, e.g. \%ENV or PSGI's $env.

Returns an enveloped result (an array).

  • First element (status) is an integer containing HTTP status code (200 means OK, 4xx caller error, 5xx function error).
  • Second element (msg) is a string containing error message, or 'OK' if status is 200.
  • Third element (result) is optional, the actual result.
  • Fourth element (meta) is called result metadata and is optional, a hash that contains extra information.

Return value: (hash)

  • 'is_gui_browser' key will be set to true if the HTTP client is a GUI browser. πŸ’–
  • 'is_text_browser' key will be set to true if the HTTP client is a text/TUI browser. πŸŽ€
  • 'is_browser' key will be set to true if either 'is_gui_browser' or 'is_text_browser' is set to true. iykyk 🌸

See also:

  • HTML::ParseBrowser
  • HTTP::BrowserDetect
  • HTTP::DetectUserAgent
  • Parse::HTTP::UserAgent
  • HTTP::headers::UserAgent

and that's the whole page bestie, go detect some user agents πŸ¦‹

perl v5.34.0 Β· 2022-06-17 Β· SHARYA...:Simple(3pm) β€” mwah, bye πŸ’œ

πŸ“¦ where this page comes from