Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
303e3de4
Commit
303e3de4
authored
Nov 17, 2017
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: fix for avatar images when gzip is turned on, fixes #5952
parent
7ccc8ae2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
13 deletions
+18
-13
pkg/api/api.go
+2
-2
pkg/api/avatar/avatar.go
+16
-11
No files found.
pkg/api/api.go
View file @
303e3de4
...
...
@@ -320,8 +320,8 @@ func (hs *HttpServer) registerRoutes() {
r
.
Any
(
"/api/gnet/*"
,
reqSignedIn
,
ProxyGnetRequest
)
// Gravatar service.
av
t
:=
avatar
.
CacheServer
()
r
.
Get
(
"/avatar/:hash"
,
av
t
.
ServeHTTP
)
av
atarCacheServer
:=
avatar
.
New
CacheServer
()
r
.
Get
(
"/avatar/:hash"
,
av
atarCacheServer
.
Handler
)
// Websocket
r
.
Any
(
"/ws"
,
hs
.
streamManager
.
Serve
)
...
...
pkg/api/avatar/avatar.go
View file @
303e3de4
...
...
@@ -24,6 +24,7 @@ import (
"github.com/grafana/grafana/pkg/log"
"github.com/grafana/grafana/pkg/setting"
"gopkg.in/macaron.v1"
)
var
gravatarSource
string
...
...
@@ -89,12 +90,12 @@ func (this *Avatar) Update() (err error) {
return
err
}
type
service
struct
{
type
CacheServer
struct
{
notFound
*
Avatar
cache
map
[
string
]
*
Avatar
}
func
(
this
*
service
)
mustInt
(
r
*
http
.
Request
,
defaultValue
int
,
keys
...
string
)
(
v
int
)
{
func
(
this
*
CacheServer
)
mustInt
(
r
*
http
.
Request
,
defaultValue
int
,
keys
...
string
)
(
v
int
)
{
for
_
,
k
:=
range
keys
{
if
_
,
err
:=
fmt
.
Sscanf
(
r
.
FormValue
(
k
),
"%d"
,
&
v
);
err
==
nil
{
defaultValue
=
v
...
...
@@ -103,8 +104,8 @@ func (this *service) mustInt(r *http.Request, defaultValue int, keys ...string)
return
defaultValue
}
func
(
this
*
service
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Reques
t
)
{
urlPath
:=
r
.
URL
.
Path
func
(
this
*
CacheServer
)
Handler
(
ctx
*
macaron
.
Contex
t
)
{
urlPath
:=
ctx
.
Req
.
URL
.
Path
hash
:=
urlPath
[
strings
.
LastIndex
(
urlPath
,
"/"
)
+
1
:
]
var
avatar
*
Avatar
...
...
@@ -126,20 +127,24 @@ func (this *service) ServeHTTP(w http.ResponseWriter, r *http.Request) {
this
.
cache
[
hash
]
=
avatar
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"image/jpeg"
)
w
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
avatar
.
data
.
Bytes
())))
w
.
Header
()
.
Set
(
"Cache-Control"
,
"private, max-age=3600"
)
ctx
.
Resp
.
Header
()
.
Add
(
"Content-Type"
,
"image/jpeg"
)
if
err
:=
avatar
.
Encode
(
w
);
err
!=
nil
{
if
!
setting
.
EnableGzip
{
ctx
.
Resp
.
Header
()
.
Add
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
avatar
.
data
.
Bytes
())))
}
ctx
.
Resp
.
Header
()
.
Add
(
"Cache-Control"
,
"private, max-age=3600"
)
if
err
:=
avatar
.
Encode
(
ctx
.
Resp
);
err
!=
nil
{
log
.
Warn
(
"avatar encode error: %v"
,
err
)
w
.
WriteHeader
(
500
)
ctx
.
WriteHeader
(
500
)
}
}
func
CacheServer
()
http
.
Handl
er
{
func
NewCacheServer
()
*
CacheServ
er
{
UpdateGravatarSource
()
return
&
service
{
return
&
CacheServer
{
notFound
:
newNotFound
(),
cache
:
make
(
map
[
string
]
*
Avatar
),
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment