feat: set global http timeouts except for streaming endpoints
related #411 Release-As: 0.16.2
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"go.senan.xyz/gonic/db"
|
||||
"go.senan.xyz/gonic/handlerutil"
|
||||
@@ -94,6 +95,10 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa
|
||||
withRequiredParams,
|
||||
withUser(dbc),
|
||||
)
|
||||
chainRaw := handlerutil.Chain(
|
||||
chain,
|
||||
slow,
|
||||
)
|
||||
|
||||
c.Handle("/getLicense", chain(resp(c.ServeGetLicence)))
|
||||
c.Handle("/ping", chain(resp(c.ServePing)))
|
||||
@@ -124,10 +129,10 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa
|
||||
c.Handle("/getLyrics", chain(resp(c.ServeGetLyrics)))
|
||||
|
||||
// raw
|
||||
c.Handle("/getCoverArt", chain(respRaw(c.ServeGetCoverArt)))
|
||||
c.Handle("/stream", chain(respRaw(c.ServeStream)))
|
||||
c.Handle("/download", chain(respRaw(c.ServeStream)))
|
||||
c.Handle("/getAvatar", chain(respRaw(c.ServeGetAvatar)))
|
||||
c.Handle("/getCoverArt", chainRaw(respRaw(c.ServeGetCoverArt)))
|
||||
c.Handle("/stream", chainRaw(respRaw(c.ServeStream)))
|
||||
c.Handle("/download", chainRaw(respRaw(c.ServeStream)))
|
||||
c.Handle("/getAvatar", chainRaw(respRaw(c.ServeGetAvatar)))
|
||||
|
||||
// browse by tag
|
||||
c.Handle("/getAlbum", chain(resp(c.ServeGetAlbum)))
|
||||
@@ -257,6 +262,15 @@ func withUser(dbc *db.DB) handlerutil.Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
func slow(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
rc := http.NewResponseController(w) //nolint:bodyclose
|
||||
_ = rc.SetWriteDeadline(time.Time{}) // set no deadline, since we're probably streaming
|
||||
_ = rc.SetReadDeadline(time.Time{}) // set no deadline, since we're probably streaming
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func checkCredsToken(password, token, salt string) bool {
|
||||
toHash := fmt.Sprintf("%s%s", password, salt)
|
||||
hash := md5.Sum([]byte(toHash))
|
||||
|
||||
Reference in New Issue
Block a user