mirror of
https://github.com/miniflux/v2.git
synced 2025-10-20 19:52:08 +00:00
feat(integrations): automatically disable googlereader/fever when not used #3543
When there is no user of Fever/GoogleReader, there is no need to expose their endpoints. This reduces quite a bit the exposition surface of miniflux, while not breaking any existing deployments, and is pretty self-contained.
This commit is contained in:
parent
10b2b36895
commit
0e28c0610a
5 changed files with 73 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
|
||||
"miniflux.app/v2/internal/http/request"
|
||||
"miniflux.app/v2/internal/http/response"
|
||||
"miniflux.app/v2/internal/http/response/json"
|
||||
"miniflux.app/v2/internal/storage"
|
||||
)
|
||||
|
@ -21,6 +22,29 @@ func newMiddleware(s *storage.Storage) *middleware {
|
|||
return &middleware{s}
|
||||
}
|
||||
|
||||
func (m *middleware) maybeUnauthorizedFever(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
feverUsed, err := m.store.IsFeverUsed()
|
||||
if err != nil {
|
||||
builder := response.New(w, r)
|
||||
builder.WithStatus(http.StatusInternalServerError)
|
||||
builder.WithHeader("Content-Type", "text/plain")
|
||||
builder.Write()
|
||||
return
|
||||
}
|
||||
|
||||
if !feverUsed {
|
||||
builder := response.New(w, r)
|
||||
builder.WithStatus(http.StatusUnauthorized)
|
||||
builder.WithHeader("Content-Type", "text/plain")
|
||||
builder.Write()
|
||||
return
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
func (m *middleware) serve(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
clientIP := request.ClientIP(r)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue