diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-10 21:36:38 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-11 13:36:38 +0800 |
commit | 8a19c6b9a25e6336be80496f0216971ae4d2475a (patch) | |
tree | 0600fe2218ec54d127ad3e41089c39511cd8b705 /modules/setting/setting.go | |
parent | 81fd8c8fb686621acfdd91a73ade75b44030ce18 (diff) | |
download | gitea-8a19c6b9a25e6336be80496f0216971ae4d2475a.tar.gz gitea-8a19c6b9a25e6336be80496f0216971ae4d2475a.zip |
Fix avatar URLs (#3069) (#3143)
* Fix avatar URLs
* import order
Diffstat (limited to 'modules/setting/setting.go')
-rw-r--r-- | modules/setting/setting.go | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 0324975702..4b01829605 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -325,6 +325,7 @@ var ( // Picture settings AvatarUploadPath string GravatarSource string + GravatarSourceURL *url.URL DisableGravatar bool EnableFederatedAvatar bool LibravatarService *libravatar.Libravatar @@ -1026,18 +1027,22 @@ func NewContext() { if DisableGravatar { EnableFederatedAvatar = false } + if EnableFederatedAvatar || !DisableGravatar { + GravatarSourceURL, err = url.Parse(GravatarSource) + if err != nil { + log.Fatal(4, "Failed to parse Gravatar URL(%s): %v", + GravatarSource, err) + } + } if EnableFederatedAvatar { LibravatarService = libravatar.New() - parts := strings.Split(GravatarSource, "/") - if len(parts) >= 3 { - if parts[0] == "https:" { - LibravatarService.SetUseHTTPS(true) - LibravatarService.SetSecureFallbackHost(parts[2]) - } else { - LibravatarService.SetUseHTTPS(false) - LibravatarService.SetFallbackHost(parts[2]) - } + if GravatarSourceURL.Scheme == "https" { + LibravatarService.SetUseHTTPS(true) + LibravatarService.SetSecureFallbackHost(GravatarSourceURL.Host) + } else { + LibravatarService.SetUseHTTPS(false) + LibravatarService.SetFallbackHost(GravatarSourceURL.Host) } } |