43 lines
822 B
Go
43 lines
822 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/rule"
|
|
"github.com/expr-lang/expr"
|
|
)
|
|
|
|
func WithRequestFuncs(r *http.Request) rule.OptionFunc {
|
|
return func(opts *rule.Options) {
|
|
funcs := []expr.Option{
|
|
setRequestURL(r),
|
|
setRequestHeaderFunc(r),
|
|
addRequestHeaderFunc(r),
|
|
delRequestHeadersFunc(r),
|
|
setRequestHostFunc(r),
|
|
}
|
|
|
|
if len(opts.Expr) == 0 {
|
|
opts.Expr = make([]expr.Option, 0)
|
|
}
|
|
|
|
opts.Expr = append(opts.Expr, funcs...)
|
|
}
|
|
}
|
|
|
|
func WithResponseFuncs(r *http.Response) rule.OptionFunc {
|
|
return func(opts *rule.Options) {
|
|
funcs := []expr.Option{
|
|
setResponseHeaderFunc(r),
|
|
addResponseHeaderFunc(r),
|
|
delResponseHeadersFunc(r),
|
|
}
|
|
|
|
if len(opts.Expr) == 0 {
|
|
opts.Expr = make([]expr.Option, 0)
|
|
}
|
|
|
|
opts.Expr = append(opts.Expr, funcs...)
|
|
}
|
|
}
|