browser.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package compatibility
  2. import (
  3. "path/filepath"
  4. "strconv"
  5. "strings"
  6. )
  7. /*
  8. FirefoxBrowserVersionForBypassUploadMetaHeaderCheck
  9. This function check if Firefox version is between 84 and 93.
  10. If yes, this function will return TRUE and upload logic should not need to handle
  11. META header for upload. If FALSE, please extract the relative filepath from the meta header.
  12. Example Firefox userAgent header:
  13. Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.02021/11/23
  14. */
  15. func FirefoxBrowserVersionForBypassUploadMetaHeaderCheck(userAgent string) bool {
  16. if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
  17. userAgentSegment := strings.Split(userAgent, " ")
  18. for _, u := range userAgentSegment {
  19. if len(u) > 4 && strings.TrimSpace(u)[:3] == "rv:" {
  20. //This is the firefox version code
  21. versionCode := strings.TrimSpace(u)[3 : len(u)-1]
  22. vcodeNumeric, err := strconv.ParseFloat(versionCode, 64)
  23. if err != nil {
  24. //Unknown version of Firefox. Just check for META anyway
  25. return false
  26. }
  27. if vcodeNumeric >= 84 && vcodeNumeric < 94 {
  28. //Special versions of Firefox. Do not check for META header
  29. return true
  30. } else {
  31. //Newer or equal to v94. Check it
  32. return false
  33. }
  34. }
  35. }
  36. }
  37. //Not Firefox.
  38. return true
  39. }
  40. //Handle browser compatibility issue regarding some special format type
  41. func BrowserCompatibilityOverrideContentType(userAgent string, filename string, contentType string) string {
  42. if strings.Contains(userAgent, "Mozilla") && strings.Contains(userAgent, "Firefox/") {
  43. //Firefox. Handle specal content-type serving
  44. if filepath.Ext(filename) == ".ai" {
  45. //Handle issue #105 for .ai file downloaded as .pdf on Firefox
  46. //https://github.com/tobychui/arozos/issues/105
  47. return "application/ai"
  48. }
  49. }
  50. return contentType
  51. }