HTTP User Agent parser for the Go programming language.

Overview

Build Status for master branch godoc.org page MIT


UserAgent is a Go library that parses HTTP User Agents. As an example:

package main

import (
    "fmt"

    "github.com/mssola/user_agent"
)

func main() {
    // The "New" function will create a new UserAgent object and it will parse
    // the given string. If you need to parse more strings, you can re-use
    // this object and call: ua.Parse("another string")
    ua := user_agent.New("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11")

    fmt.Printf("%v\n", ua.Mobile())   // => false
    fmt.Printf("%v\n", ua.Bot())      // => false
    fmt.Printf("%v\n", ua.Mozilla())  // => "5.0"

    fmt.Printf("%v\n", ua.Platform()) // => "X11"
    fmt.Printf("%v\n", ua.OS())       // => "Linux x86_64"

    name, version := ua.Engine()
    fmt.Printf("%v\n", name)          // => "AppleWebKit"
    fmt.Printf("%v\n", version)       // => "537.11"

    name, version = ua.Browser()
    fmt.Printf("%v\n", name)          // => "Chrome"
    fmt.Printf("%v\n", version)       // => "23.0.1271.97"

    // Let's see an example with a bot.

    ua.Parse("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")

    fmt.Printf("%v\n", ua.Bot())      // => true

    name, version = ua.Browser()
    fmt.Printf("%v\n", name)          // => Googlebot
    fmt.Printf("%v\n", version)       // => 2.1
}

If you want to read the full API documentation simply check godoc.

Installation

go get -u github.com/mssola/user_agent

Contributing

Do you want to contribute with code, or to report an issue you are facing? Read the CONTRIBUTING.md file.

Changelog

Read the CHANGELOG.md file.

License

Copyright (c) 2012-2021 Miquel Sabaté Solà

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Issues
  • Adds the Adsense bot (mobile)

    Adds the Adsense bot (mobile)

    According to the following list of Google crawlers, I have changed the detection of Google mobile crawlers to deal with the one of Google Ads.

    Google crawlers (user agents)

    opened by rvflash 6
  • Edge Detecting as Chrome

    Edge Detecting as Chrome

    In using this on the Mattermost project we have found that it detects Edge as Chrome. I'm not sure if it's limited to a certain version of Edge or all Edge versions. The version I'm running is Edge 38.xxxx (EdgeHTML 14.xxx). It's detecting as Chrome 51.

    Is this a known issue or bug? Either way can we do anything to help resolve it? Thanks.

    needs info 
    opened by moonmeister 6
  • Shorter Linux tagging

    Shorter Linux tagging

    Question: Currently, Linux is being tagged as "Linux x86_64" for the OS part. It would be nice if it was just "Linux". I'll be happy to write up little PR for this, but I just wanted your opinion on it first.

    One proposal for a solution would be to check if "Linux" appears in the OS name and then split on any spaces and take the first part. I don't know if this would work for all Linux variants.

    opened by dlebech 6
  • Fix detection of Firefox on iPad

    Fix detection of Firefox on iPad

    Provide a general description of the changes in your pull request. If this pull request fixes a known issue, please tag it as well (e.g.: Fixes #1).

    Before submitting a PR make sure the following things have been done (and denote this by checking the relevant checkboxes):

    • [X] The commits are consistent with the contribution guidelines.
    • [X] You've added tests (if possible) to cover your change(s).
    • [X] All tests and style checkers are passing (make ci).
    • [X] You've updated the changelog.
    • [ ] You've updated the readme (if relevant).

    Thanks for contributing to user_agent!

    opened by nono 5
  • Add additional WebKit browsers

    Add additional WebKit browsers

    Add support for the following:

    • Coc Coc Browser
    • Headless Chrome
    • iOS WebViews

    Fixes #82

    Before submitting a PR make sure the following things have been done (and denote this by checking the relevant checkboxes):

    • [x] The commits are consistent with the contribution guidelines.
    • [x] You've added tests (if possible) to cover your change(s).
    • [x] All tests and style checkers are passing (make ci).
    • [x] You've updated the changelog.
    • [x] You've updated the readme (if relevant).
    opened by kylekizirian 3
  • Support of Microsoft Edge is missing

    Support of Microsoft Edge is missing

    Description

    Support of Microsoft Edge is missing

    Steps to reproduce

    1. Get UA from Microsoft Edge
    • Browser name = "Edge"
    • currently getting Browser name = "Chrome"

    user_agent version

    With a git commit SHA if possible.

    Go version and interpreter

    $ go version
    

    Operating system

    The operating system and the exact version you are using. If you are using Linux, it may be useful to know which distribution you are using and what did you do in order to install go.

    bug 
    opened by asinha08 3
  • release a new tagged version

    release a new tagged version

    Hello !

    Could you release a new tagged version ? There are many changes since the latest tag: https://github.com/mssola/user_agent/compare/v0.4.1...master

    Do you have any plan to release future tags more frequently ? Do you use semver ?

    Thank you.

    opened by pierrre 3
  • Add support for IE compatibility Trident tokens.

    Add support for IE compatibility Trident tokens.

    I had a few users that are apparently in IE 7 compatibility mode on IE 8 and IE 10. I had to look this up but apparently for IE 8, 9, and 10, the Trident token is a more reliable representation of browser version.

    http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx#VerToken http://msdn.microsoft.com/en-us/library/ie/ms537503(v=vs.85).aspx#TriToken

    Warning: The Tablet test had MSIE 7.0 and Trident/6.0. According to the document above, this should be IE 10 but it was being tested for IE 7. I've made the change in this commit.

    opened by pnelson 3
  • panic: runtime error: index out of range

    panic: runtime error: index out of range

    More user agents that panic:

    Mozilla/5.0 (Linux; U) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4
    Mozilla/4.0 (compatible; MSIE6.0; Windows NT 5.0; .NET CLR 1.1.4322)
    
    opened by vmihailenco 3
  • panic: runtime error: index out of range

    panic: runtime error: index out of range

    Another panic parsing this:

    userAgent := &ua.UserAgent{}
    userAgent.Parse("Opera/9.80 (Windows NT 6.0; WOW64) Presto/2.12.388 Version/12.15")
    
    opened by vmihailenco 3
  • Electron Support

    Electron Support

    When Electron Apps(https://electron.atom.io/) are used it detects strangely. I'm on a mac and it's detecting electron apps as Safari, but then it's detecting the version of Safari not as the actual Safari version, nor the version of Electron, but the version of the app.

    Franz detects as:

    [2017/09/15 16:36:38 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Franz/4.0.4 Chrome/52.0.2743.82 Electron/1.3.1 Safari/537.36
    [2017/09/15 16:36:38 PDT] [DEBG] Detected Client: Safari 4.0.4
    

    The Mattermost App Detects as:

    [2017/09/15 16:37:16 PDT] [DEBG] User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Mattermost/3.7.1 Chrome/56.0.2924.87 Electron/1.6.11 Safari/537.36
    [2017/09/15 16:37:16 PDT] [DEBG] Detected Client: Mattermost App - Safari 3.7.1
    

    I'm not entirely sure how electron works but it seems like I should either be give Electron as the Browser and the Version of Electron in use, or if electron is simply using a Safari Window then the correct version of Safari (or the windows/linux browser counterpart).

    opened by moonmeister 2
  • HeadlessChrome ua parse error

    HeadlessChrome ua parse error

    Description

    HeadlessChrome ua parse error

    Steps to reproduce

    Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/97.0.4691.0 Safari/537.36

    image

    • Expected behavior: browser.name is HeadlessChrome
    • Actual behavior: browser.name is Safari

    user_agent version

    v0.5.3

    Go version and interpreter

    go version go1.17.6 linux/amd64

    Operating system

    debian 11

    opened by ttttmr 0
  • PhantomJS user agent

    PhantomJS user agent

    Description

    The user agent name for PhantomJS is being reported as Safari when it probably should be PhantomJS.

    Steps to reproduce

    Get name value of PhantomJS user agent: Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1

    • Expected behavior: user agent name is PhantomJS
    • Actual behavior: user agent name is Safari

    user_agent version

    0.5.3

    Go version and interpreter

    1.16.6

    Code example

    package main
    
    import (
    	"fmt"
    
    	"github.com/mssola/user_agent"
    )
    
    func main() {
    	ua := user_agent.New(
    		"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1")
    
    	name, _ := ua.Browser()
    	fmt.Printf("%v\n", name) // This should be "PhantomJS" instead of "Safari"
    }
    

    Golang playground example: https://play.golang.org/p/2cXcLn1Kzi3

    bug 
    opened by thompiler 0
  • Chrome webview

    Chrome webview

    this user agent will receive android 4 for browser name

    Mozilla/5.0 (Linux; Android 10; SM-T510 Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/91.0.4472.120 Safari/537.36 [FB_IAB/FB4A;FBAV/325.0.0.36.170;]
    
    opened by vahid-sohrabloo 4
  • Browser type exported (public), does it need to be?

    Browser type exported (public), does it need to be?

    Description

    I found this library (appreciate your OSS contribution) and was looking thru the GoDoc to gain an understanding of the package's API structure.

    I was wondering about the Browser type. It's part of the public API, it doesn't seem to be exposed by any of the public functions or as a public field of the other exported types. To me, it appears that this type should not be exported, and should be renamed from Browser to browser.

    It's also possible that perhaps that the receiver method:

    func (p *UserAgent) Browser() (string, string)
    

    Should instead be exposed as:

    func (p *UserAgent) Browser() Browser
    

    What do you think?

    opened by aren55555 0
  • A mobile user agent is reported as a non-mobile user agent.

    A mobile user agent is reported as a non-mobile user agent.

    Description

    The following ua containing the keyword iPhone wants to be reported as a mobile ua:

    Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Jike/7.6.7 /sa-sdk-ios/sensors-verify/track.midway.run?jike

    Steps to reproduce

    import "github.com/mssola/user_agent"
    
    func main() {
    	ua := "Mozilla/5.0 (iPhone; CPU iPhone OS 13_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Jike/7.6.7 /sa-sdk-ios/sensors-verify/track.midway.run?jike"
    	user_agent.New(ua).Mobile() // True is expected, but false is got.
    }
    

    user_agent version

    v0.5.2

    Go version and interpreter

    go version go1.14.2 darwin/amd64

    Operating system

    macOS Mojave 10.14.6(18G6032)

    bug 
    opened by gaojunhuicavon 0
Releases(v0.5.3)
  • v0.5.3(May 19, 2021)

  • v0.5.2(Apr 18, 2020)

  • v0.5.1(Jan 10, 2020)

    • 00a868fa17e7 add Firefox for iOS
    • 8c16c37f4e07 Add go.mod
    • 7e313fc62553 Use CodeLingo to Address Further Issues
    • 95b0c164394f Fix function comments based on best practices from Effective Go
    • 1df9e04ee4f5 test: mobile Yandex Browser
    • 6eb76c60b5e8 Add Yandex browser
    • 8b3999083770 Updating license notice
    • 82f141dea4a8 Detect Chrome for iOS correctly
    • 5723c361ed97 Facebook App Handling
    • 57c32981bd5f Add a new google bot user agent format
    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Nov 20, 2018)

    Newly supported and improvements

    • f659b9863849 Added support for Microsoft Edge
    • 783ec61292ae Precompile regular expressions
    • 78413629666f Added support for Dalvik user agent parsing
    • 0319fcf00bfd Improved bot support (also e25e612b37a4)
    • 6e7843e05771 Add Chromium support and Ubuntu specific tests
    • 3335cae017e7 Add OSInfo function to user agent (also 7286ca6abc28)
    • 6fe362d7cd64 Detect updated UA for Googlebot
    • 1438bfba89d7 Adds the Adsense bot (mobile)

    Fixes

    • 8d86c2cf88bf Fixed bug when extracting windows 10
    • 9d00ff9e4202 Fixed bug on mobile Firefox browsers running on Android OS versions that report their version number inline.

    Other

    • 63395b193f8812526305bec75ea7117262a124aa Improved testing infrastructure (also 63395b193f8812526305bec75ea7117262a124aa)
    Source code(tar.gz)
    Source code(zip)
Owner
Miquel Sabaté Solà
Free software developer. Working with containers @SUSE.
Miquel Sabaté Solà
Speak HTTP like a local. (the simple, intuitive HTTP console, golang version)

http-gonsole This is the Go port of the http-console. Speak HTTP like a local Talking to an HTTP server with curl can be fun, but most of the time it'

mattn 65 Jul 14, 2021
Http client call for golang http api calls

httpclient-call-go This library is used to make http calls to different API services Install Package go get

pzenteno 14 Mar 8, 2022
fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client.

fhttp The f stands for flex. fhttp is a fork of net/http that provides an array of features pertaining to the fingerprint of the golang http client. T

Flexagon 61 Jun 10, 2022
NATS HTTP Round Tripper - This is a Golang http.RoundTripper that uses NATS as a transport.

This is a Golang http.RoundTripper that uses NATS as a transport. Included is a http.RoundTripper for clients, a server that uses normal HTTP Handlers and any existing http handler mux and a Caddy Server transport.

R.I.Pienaar 75 Jun 14, 2022
Simple HTTP package that wraps net/http

Simple HTTP package that wraps net/http

Kris 0 Jan 17, 2022
Http-conection - A simple example of how to establish a HTTP connection using Golang

A simple example of how to establish a HTTP connection using Golang

Jonathan Gonzaga 0 Feb 1, 2022
Full-featured, plugin-driven, extensible HTTP client toolkit for Go

gentleman Full-featured, plugin-driven, middleware-oriented toolkit to easily create rich, versatile and composable HTTP clients in Go. gentleman embr

Tom 957 Jun 22, 2022
An enhanced http client for Golang

go-http-client An enhanced http client for Golang Documentation on go.dev ?? This package provides you a http client package for your http requests. Y

Furkan Bozdag 40 May 23, 2022
An enhanced HTTP client for Go

Heimdall Description Installation Usage Making a simple GET request Creating a hystrix-like circuit breaker Creating a hystrix-like circuit breaker wi

Gojek 2.3k Jun 24, 2022
Enriches the standard go http client with retry functionality.

httpRetry Enriches the standard go http client with retry functionality using a wrapper around the Roundtripper interface. The advantage of this libra

Alexander Gehres 20 May 10, 2022
Go (golang) http calls with retries and backoff

pester pester wraps Go's standard lib http client to provide several options to increase resiliency in your request. If you experience poor network co

Seth Ammons 590 Jun 20, 2022
http client for golang

Request HTTP client for golang, Inspired by Javascript-axios Python-request. If you have experience about axios or requests, you will love it. No 3rd

Monaco.HappyHacking 206 Jun 24, 2022
Simple HTTP and REST client library for Go

Resty Simple HTTP and REST client library for Go (inspired by Ruby rest-client) Features section describes in detail about Resty capabilities Resty Co

Go Resty 6.3k Jun 26, 2022
A nicer interface for golang stdlib HTTP client

rq A nicer interface for golang stdlib HTTP client Documents rq: here client: here jar: here Why? Because golang HTTP client is a pain in the a... Fea

Ddo 40 Jan 23, 2022
A Go HTTP client library for creating and sending API requests

Sling Sling is a Go HTTP client library for creating and sending API requests. Slings store HTTP Request properties to simplify sending requests and d

Dalton Hubble 1.4k Jun 19, 2022
HTTP Load Testing And Benchmarking Tool

GBench HTTP Load Testing And Benchmarking Tool inspired by Apache Benchmark and Siege. Requirements You need Golang installed and ready on your system

Sasan Rose 16 Jan 2, 2020
HTTP/HTTPS load testing and benchmarking tool

Introduction I wrote that code because: (the obvious reason::I love to write code in Go) We are working so hard to optimize our servers - why shouldn'

Uri Shamay 430 Jun 20, 2022
An HTTP proxy library for Go

Introduction Package goproxy provides a customizable HTTP proxy library for Go (golang), It supports regular HTTP proxy, HTTPS through CONNECT, and "h

Elazar Leibovich 4.8k Jun 26, 2022
Useful HTTP middlewares

This project contains middlewares that I often found myself reimplementing in new projects. In addition, it includes a middleware that logs in a forma

Kevin Burke 19 Apr 16, 2022