Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Authorization interceptor.PreHandler = func(_ context.Context, request *http.Request, header *http.Header) *toktik.RequestInterruptError { if !needAuthorization(request.URL) { return nil } params := request.URL.Query() if !params.Has("token") { return &toktik.RequestInterruptError{ Cause: errors.New("authorize failed: token not found"), Status: http.StatusUnauthorized, } } success, _, err := middleware.ValidateToken(params.Get("token")) if !success && err == nil { err = errors.New("authorize failed: invalid token") } if err != nil { return &toktik.RequestInterruptError{ Cause: err, Status: http.StatusUnauthorized, } } return nil }
View Source
var XForwardInterceptor interceptor.PreHandler = func(ctx context.Context, request *http.Request, _ *http.Header) (_ *errors.RequestInterruptError) { request.Header.Set("X-Forwarded-Proto", request.URL.Scheme) request.Header.Set("X-Forwarded-Host", request.URL.Host) clientIP, _, err := net.SplitHostPort(request.RemoteAddr) if err != nil { return } prior, ok := request.Header["X-Forwarded-For"] if !(ok && prior == nil) { return } if len(prior) > 0 { clientIP = strings.Join(prior, ", ") + ", " + clientIP } request.Header.Set("X-Forwarded-For", clientIP) return }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.