Skip to content

Commit

Permalink
new useragent lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Dawid Bialy committed Feb 23, 2023
1 parent ccfc67d commit e8540d8
Show file tree
Hide file tree
Showing 19 changed files with 724 additions and 1,210 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/davewhit3/traefik-cf-device-detector

go 1.19

require github.com/mssola/useragent v1.0.0
require github.com/mileusna/useragent v1.2.1
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/mssola/useragent v1.0.0 h1:WRlDpXyxHDNfvZaPEut5Biveq86Ze4o4EMffyMxmH5o=
github.com/mssola/useragent v1.0.0/go.mod h1:hz9Cqz4RXusgg1EdI4Al0INR62kP7aPSRNHnpU+b85Y=
github.com/mileusna/useragent v1.2.1 h1:p3RJWhi3LfuI6BHdddojREyK3p6qX67vIfOVMnUIVr0=
github.com/mileusna/useragent v1.2.1/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc=
12 changes: 6 additions & 6 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"os"
"strconv"

"github.com/mssola/useragent"
"github.com/mileusna/useragent"
)

const (
Expand Down Expand Up @@ -57,12 +57,12 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
}

func (mw *CfDeviceDetector) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
ua := useragent.New(req.Header.Get(UserAgentHeader))
ua := useragent.Parse(req.Header.Get(UserAgentHeader))

req.Header.Set(DeviceIsMobileHeader, strconv.FormatBool(ua.Mobile()))
req.Header.Set(DeviceIsDesktopHeader, strconv.FormatBool(!ua.Mobile()))
req.Header.Set(DeviceIsTabletHeader, strconv.FormatBool(false))
req.Header.Set(DeviceIsSmartTVHeader, strconv.FormatBool(false))
req.Header.Set(DeviceIsMobileHeader, strconv.FormatBool(ua.Mobile))
req.Header.Set(DeviceIsDesktopHeader, strconv.FormatBool(ua.Desktop))
req.Header.Set(DeviceIsTabletHeader, strconv.FormatBool(ua.Tablet))
req.Header.Set(DeviceIsSmartTVHeader, strconv.FormatBool(!ua.Tablet && !ua.Desktop && !ua.Mobile))

mw.next.ServeHTTP(rw, req)
}
4 changes: 4 additions & 0 deletions vendor/github.com/mileusna/useragent/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/mileusna/useragent/LICENSE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

99 changes: 99 additions & 0 deletions vendor/github.com/mileusna/useragent/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 81 additions & 0 deletions vendor/github.com/mileusna/useragent/is.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e8540d8

Please sign in to comment.