This commit is contained in:
parent
654610ecd3
commit
3b89ea41e7
2 changed files with 17 additions and 8 deletions
|
@ -20,11 +20,13 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
|
||||||
mn := strings.Split(q.Get("mn"), ",")
|
mn := strings.Split(q.Get("mn"), ",")
|
||||||
|
|
||||||
if len(mvi) <= 0 {
|
if len(mvi) <= 0 {
|
||||||
|
w.WriteHeader(400)
|
||||||
io.WriteString(w, "No `mvi` in query parameters")
|
io.WriteString(w, "No `mvi` in query parameters")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(mn) <= 0 {
|
if len(mn) <= 0 {
|
||||||
|
w.WriteHeader(400)
|
||||||
io.WriteString(w, "No `mn` in query parameters")
|
io.WriteString(w, "No `mn` in query parameters")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,6 +37,7 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
|
||||||
parts := strings.Split(strings.ToLower(host), ".")
|
parts := strings.Split(strings.ToLower(host), ".")
|
||||||
|
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
|
w.WriteHeader(400)
|
||||||
io.WriteString(w, "Invalid hostname.")
|
io.WriteString(w, "Invalid hostname.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -49,6 +52,7 @@ func videoplayback(w http.ResponseWriter, req *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if disallowed {
|
if disallowed {
|
||||||
|
w.WriteHeader(401)
|
||||||
io.WriteString(w, "Non YouTube domains are not supported.")
|
io.WriteString(w, "Non YouTube domains are not supported.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
21
main.go
21
main.go
|
@ -96,6 +96,8 @@ var version string
|
||||||
|
|
||||||
var h3s bool
|
var h3s bool
|
||||||
|
|
||||||
|
var programInit = time.Now()
|
||||||
|
|
||||||
type ConnectionWatcher struct {
|
type ConnectionWatcher struct {
|
||||||
totalEstablished int64
|
totalEstablished int64
|
||||||
established int64
|
established int64
|
||||||
|
@ -134,14 +136,15 @@ func (cw *ConnectionWatcher) OnStateChange(conn net.Conn, state http.ConnState)
|
||||||
var cw ConnectionWatcher
|
var cw ConnectionWatcher
|
||||||
|
|
||||||
type statusJson struct {
|
type statusJson struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
RequestCount int64 `json:"requestCount"`
|
Uptime time.Duration `json:"uptime"`
|
||||||
RequestPerSecond int64 `json:"requestPerSecond"`
|
RequestCount int64 `json:"requestCount"`
|
||||||
RequestPerMinute int64 `json:"requestPerMinute"`
|
RequestPerSecond int64 `json:"requestPerSecond"`
|
||||||
TotalEstablished int64 `json:"totalEstablished"`
|
RequestPerMinute int64 `json:"requestPerMinute"`
|
||||||
EstablishedConnections int64 `json:"establishedConnections"`
|
TotalEstablished int64 `json:"totalEstablished"`
|
||||||
ActiveConnections int64 `json:"activeConnections"`
|
EstablishedConnections int64 `json:"establishedConnections"`
|
||||||
IdleConnections int64 `json:"idleConnections"`
|
ActiveConnections int64 `json:"activeConnections"`
|
||||||
|
IdleConnections int64 `json:"idleConnections"`
|
||||||
RequestsForbidden struct {
|
RequestsForbidden struct {
|
||||||
Videoplayback int64 `json:"videoplayback"`
|
Videoplayback int64 `json:"videoplayback"`
|
||||||
Vi int64 `json:"vi"`
|
Vi int64 `json:"vi"`
|
||||||
|
@ -151,6 +154,7 @@ type statusJson struct {
|
||||||
|
|
||||||
var stats_ = statusJson{
|
var stats_ = statusJson{
|
||||||
Version: version + "-" + runtime.GOARCH,
|
Version: version + "-" + runtime.GOARCH,
|
||||||
|
Uptime: 0,
|
||||||
RequestCount: 0,
|
RequestCount: 0,
|
||||||
RequestPerSecond: 0,
|
RequestPerSecond: 0,
|
||||||
RequestPerMinute: 0,
|
RequestPerMinute: 0,
|
||||||
|
@ -182,6 +186,7 @@ func root(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
func stats(w http.ResponseWriter, req *http.Request) {
|
func stats(w http.ResponseWriter, req *http.Request) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
stats_.Uptime = time.Duration(time.Since(programInit).Seconds())
|
||||||
stats_.TotalEstablished = int64(cw.totalEstablished)
|
stats_.TotalEstablished = int64(cw.totalEstablished)
|
||||||
stats_.EstablishedConnections = int64(cw.established)
|
stats_.EstablishedConnections = int64(cw.established)
|
||||||
// stats_.ActiveConnections = int64(cw.active)
|
// stats_.ActiveConnections = int64(cw.active)
|
||||||
|
|
Loading…
Reference in a new issue