Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
62a90409
Commit
62a90409
authored
11 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
run the gzip handler on the status page
parent
2ded47fb
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fe/http.go
+15
-10
15 additions, 10 deletions
fe/http.go
with
15 additions
and
10 deletions
fe/http.go
+
15
−
10
View file @
62a90409
...
@@ -19,14 +19,6 @@ import (
...
@@ -19,14 +19,6 @@ import (
)
)
// HTTP redirector.
// HTTP redirector.
//
// All user-facing traffic reaches the redirector first (this is
// where the first-level, high-ttl redirection points to).
//
// The purpose of the HTTP redirector is two-fold: sources will be
// proxied to the master icecast server, while clients will be served
// a .m3u file directly pointing at the relays.
//
type
HttpRedirector
struct
{
type
HttpRedirector
struct
{
domain
string
domain
string
client
*
radioai
.
RadioAPI
client
*
radioai
.
RadioAPI
...
@@ -40,7 +32,9 @@ func NewHttpRedirector(client *radioai.RadioAPI, domain string) *HttpRedirector
...
@@ -40,7 +32,9 @@ func NewHttpRedirector(client *radioai.RadioAPI, domain string) *HttpRedirector
}
}
}
}
// Return an active node, chosen randomly.
// Return an active node, chosen randomly (this is currently our load
// balancing policy, since there is no status information about the
// nodes yet).
func
(
h
*
HttpRedirector
)
pickActiveNode
()
string
{
func
(
h
*
HttpRedirector
)
pickActiveNode
()
string
{
nodes
,
_
:=
h
.
client
.
GetNodes
()
nodes
,
_
:=
h
.
client
.
GetNodes
()
if
nodes
!=
nil
&&
len
(
nodes
)
>
0
{
if
nodes
!=
nil
&&
len
(
nodes
)
>
0
{
...
@@ -126,12 +120,20 @@ func (h *HttpRedirector) serveStatusPage(w http.ResponseWriter, r *http.Request)
...
@@ -126,12 +120,20 @@ func (h *HttpRedirector) serveStatusPage(w http.ResponseWriter, r *http.Request)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
return
}
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"text/html; charset=utf-8"
)
w
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
buf
.
Len
()))
w
.
Write
(
buf
.
Bytes
())
w
.
Write
(
buf
.
Bytes
())
}
}
func
(
h
*
HttpRedirector
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
func
(
h
*
HttpRedirector
)
ServeHTTP
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
r
.
URL
.
Path
==
""
||
r
.
URL
.
Path
==
"/"
{
if
r
.
URL
.
Path
==
""
||
r
.
URL
.
Path
==
"/"
{
h
.
serveStatusPage
(
w
,
r
)
// Serve the status page through a GZIPHandler. Binds
// to h using function closure.
handler
:=
GZIPHandler
(
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
h
.
serveStatusPage
(
w
,
r
)
}),
nil
)
handler
.
ServeHTTP
(
w
,
r
)
}
else
if
r
.
Method
==
"SOURCE"
{
}
else
if
r
.
Method
==
"SOURCE"
{
h
.
serveSource
(
w
,
r
)
h
.
serveSource
(
w
,
r
)
}
else
{
}
else
{
...
@@ -139,11 +141,14 @@ func (h *HttpRedirector) ServeHTTP(w http.ResponseWriter, r *http.Request) {
...
@@ -139,11 +141,14 @@ func (h *HttpRedirector) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
}
}
// Run starts the HTTP server on the given addr. Does not return.
func
(
h
*
HttpRedirector
)
Run
(
addr
,
staticDir
,
templateDir
string
)
{
func
(
h
*
HttpRedirector
)
Run
(
addr
,
staticDir
,
templateDir
string
)
{
h
.
template
=
template
.
Must
(
h
.
template
=
template
.
Must
(
template
.
ParseGlob
(
template
.
ParseGlob
(
filepath
.
Join
(
templateDir
,
"*.html"
)))
filepath
.
Join
(
templateDir
,
"*.html"
)))
// The purpose of the odd usage of GZIPHandler is to bypass it
// on SOURCE and m3u requests. May not be necessary though.
mux
:=
http
.
NewServeMux
()
mux
:=
http
.
NewServeMux
()
mux
.
HandleFunc
(
mux
.
HandleFunc
(
"/static/"
,
"/static/"
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment