summaryrefslogtreecommitdiffstats
path: root/modules/setting/setting.go
diff options
context:
space:
mode:
authorEthan Koenig <ethantkoenig@gmail.com>2017-12-03 03:55:13 -0800
committerLunny Xiao <xiaolunwen@gmail.com>2017-12-03 19:55:13 +0800
commitab62da283aa20475109eba907324f55123d7e3c6 (patch)
treea08bb1753ff39d9ecc74afc42374ba614c67d8bb /modules/setting/setting.go
parent7bab3d2fb1d75ac29ad6a9b11203ea358b1979d3 (diff)
downloadgitea-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.go23
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)
}
}