browser.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package compatibility
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. /*
  7. FirefoxBrowserVersionForBypassUploadMetaHeaderCheck
  8. This function check if Firefox version is between 84 and 93.
  9. If yes, this function will return TRUE and upload logic should not need to handle
  10. META header for upload. If FALSE, please extract the relative filepath from the meta header.
  11. Example Firefox userAgent header:
  12. Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.02021/11/23
  13. */
  14. func FirefoxBrowserVersionForBypassUploadMetaHeaderCheck(userAgent string) bool {
  15. if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
  16. userAgentSegment := strings.Split(userAgent, " ")
  17. for _, u := range userAgentSegment {
  18. if len(u) > 4 && strings.TrimSpace(u)[:3] == "rv:" {
  19. //This is the firefox version code
  20. versionCode := strings.TrimSpace(u)[3 : len(u)-1]
  21. vcodeNumeric, err := strconv.ParseFloat(versionCode, 64)
  22. if err != nil {
  23. //Unknown version of Firefox. Just check for META anyway
  24. return false
  25. }
  26. if vcodeNumeric >= 84 && vcodeNumeric < 94 {
  27. //Special versions of Firefox. Do not check for META header
  28. return true
  29. } else {
  30. //Newer or equal to v94. Check it
  31. return false
  32. }
  33. }
  34. }
  35. }
  36. //Not Firefox.
  37. return true
  38. }