mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Store client IP address in request context
This commit is contained in:
parent
c1e1506720
commit
c9f9dd3262
9 changed files with 46 additions and 19 deletions
21
middleware/client_ip.go
Normal file
21
middleware/client_ip.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||
// Use of this source code is governed by the Apache 2.0
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package middleware // import "miniflux.app/middleware"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"miniflux.app/http/request"
|
||||
)
|
||||
|
||||
// ClientIP stores in the real client IP address in the context.
|
||||
func (m *Middleware) ClientIP(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, request.ClientIPContextKey, request.FindClientIP(r))
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue