Recent

Author Topic: UserAgent => OS, browser etc  (Read 2863 times)

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
UserAgent => OS, browser etc
« on: January 18, 2019, 12:49:00 pm »
Can anyone share the function for parsing the useragent (HTTP header) on the OS and browser (for example)?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: UserAgent => OS, browser etc
« Reply #1 on: January 18, 2019, 02:00:13 pm »
IIRC UserAgent is a free-form string without a strictly defined format. There are certain conventions like "program/9.89 (extensions)" which you may be able to parse but it's not guaranteed that it will work always and for each string.

That said, you could take the most common UserAgents, try to find their commonalities and build a simple parser. It shouldn't be too difficult.

Or you could try to translate any of the gazillions JS/PHP/Python implementations out there, just a google search away :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: UserAgent => OS, browser etc
« Reply #2 on: January 18, 2019, 05:04:42 pm »
IIRC UserAgent is a free-form string without a strictly defined format. There are certain conventions like "program/9.89 (extensions)" which you may be able to parse but it's not guaranteed that it will work always and for each string.

That said, you could take the most common UserAgents, try to find their commonalities and build a simple parser. It shouldn't be too difficult.

Or you could try to translate any of the gazillions JS/PHP/Python implementations out there, just a google search away :)
Yes, I know it's not standardized and I can parse this string myself. I agree with You. But if there is a ready-made solution, why not take advantage of this solution?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: UserAgent => OS, browser etc
« Reply #3 on: January 18, 2019, 05:47:10 pm »
I don't know of any but maybe one of the networking libraries or web development frameworks has something similar. Look in the Web Deveopment Portal to get links to them.
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1312
    • Lebeau Software
Re: UserAgent => OS, browser etc
« Reply #4 on: January 19, 2019, 02:30:38 am »
IIRC UserAgent is a free-form string without a strictly defined format. There are certain conventions like "program/9.89 (extensions)" which you may be able to parse but it's not guaranteed that it will work always and for each string.

Web browsers, for instance, don't commonly follow that "simple" convention, they have a much more elaborate format:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent

Quote
Syntax

Code: [Select]
User-Agent: <product> / <product-version> <comment>

Common format for web browsers:

User-Agent: Mozilla/<version> (<system-information>) <platform> (<platform-details>) <extensions>

Directives

<product>
    A product identifier

<product-version>
    A version number of the product.

<comment>
    Zero or more comments containing sub product information, for example.

User-Agent is formally defined in RFC 2616 Section 14.43 and RFC 7231 Section 5.5.3.
« Last Edit: January 19, 2019, 02:35:47 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Renat.Su

  • Full Member
  • ***
  • Posts: 230
    • Renat.Su
Re: UserAgent => OS, browser etc
« Reply #5 on: January 19, 2019, 11:12:55 am »
Thank You! Very useful information

 

TinyPortal © 2005-2018