1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-16 18:01:37 +00:00

Add configurable HTTPS flag for secure cookie flag

This commit is contained in:
Frédéric Guillot 2017-12-28 20:34:18 -08:00
parent a63105e13b
commit 7c19febd73
8 changed files with 33 additions and 24 deletions

View file

@ -8,6 +8,7 @@ import (
"net/http"
"time"
"github.com/miniflux/miniflux/config"
"github.com/miniflux/miniflux/helper"
"github.com/miniflux/miniflux/locale"
"github.com/miniflux/miniflux/logger"
@ -16,6 +17,7 @@ import (
"github.com/miniflux/miniflux/storage"
"github.com/gorilla/mux"
"github.com/tomasen/realip"
)
// HandlerFunc is an application HTTP handler.
@ -23,6 +25,7 @@ type HandlerFunc func(ctx *Context, request *Request, response *Response)
// Handler manages HTTP handlers and middlewares.
type Handler struct {
cfg *config.Config
store *storage.Storage
translator *locale.Translator
template *template.Engine
@ -34,7 +37,11 @@ type Handler struct {
func (h *Handler) Use(f HandlerFunc) http.Handler {
return h.middleware.WrapFunc(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer helper.ExecutionTime(time.Now(), r.URL.Path)
logger.Debug("[HTTP] %s %s", r.Method, r.URL.Path)
logger.Debug("[HTTP] %s %s %s", realip.RealIP(r), r.Method, r.URL.Path)
if r.Header.Get("X-Forwarded-Proto") == "https" {
h.cfg.IsHTTPS = true
}
ctx := NewContext(w, r, h.store, h.router, h.translator)
request := NewRequest(w, r)
@ -51,8 +58,9 @@ func (h *Handler) Use(f HandlerFunc) http.Handler {
}
// NewHandler returns a new Handler.
func NewHandler(store *storage.Storage, router *mux.Router, template *template.Engine, translator *locale.Translator, middleware *middleware.Chain) *Handler {
func NewHandler(cfg *config.Config, store *storage.Storage, router *mux.Router, template *template.Engine, translator *locale.Translator, middleware *middleware.Chain) *Handler {
return &Handler{
cfg: cfg,
store: store,
translator: translator,
router: router,