diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-12-03 03:55:13 -0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-03 19:55:13 +0800 |
commit | ab62da283aa20475109eba907324f55123d7e3c6 (patch) | |
tree | a08bb1753ff39d9ecc74afc42374ba614c67d8bb /modules/setting/setting.go | |
parent | 7bab3d2fb1d75ac29ad6a9b11203ea358b1979d3 (diff) | |
download | gitea-ab62da283aa20475109eba907324f55123d7e3c6.tar.gz gitea-ab62da283aa20475109eba907324f55123d7e3c6.zip |
Fix avatar URLs (#3069)
* 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 db6f749c06..f8da952413 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -326,6 +326,7 @@ var ( // Picture settings AvatarUploadPath string GravatarSource string + GravatarSourceURL *url.URL DisableGravatar bool EnableFederatedAvatar bool LibravatarService *libravatar.Libravatar @@ -1027,18 +1028,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) } } |