MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / NewRejectHTTPAuth

Function NewRejectHTTPAuth

auth/rejecthttp.go:18–47  ·  view source on GitHub ↗
(u *url.URL, logger *clog.CondLogger)

Source from the content-addressed store, hash-verified

16}
17
18func NewRejectHTTPAuth(u *url.URL, logger *clog.CondLogger) (*RejectHTTPAuth, error) {
19 values, err := url.ParseQuery(u.RawQuery)
20 if err != nil {
21 return nil, err
22 }
23 scheme, _ := strings.CutPrefix(strings.ToLower(u.Scheme), "reject-")
24 target := &url.URL{
25 Scheme: scheme,
26 User: u.User,
27 Host: u.Host,
28 Path: u.Path,
29 RawPath: u.RawPath,
30 RawQuery: values.Get("qs"),
31 }
32 xf, _ := strconv.ParseBool(values.Get("x-forwarded"))
33 method := values.Get("method")
34 return &RejectHTTPAuth{
35 proxy: &httputil.ReverseProxy{
36 Rewrite: func(r *httputil.ProxyRequest) {
37 r.SetURL(target)
38 if xf {
39 r.SetXForwarded()
40 }
41 if method != "" {
42 r.Out.Method = method
43 }
44 },
45 },
46 }, nil
47}
48
49func (a *RejectHTTPAuth) Validate(ctx context.Context, w http.ResponseWriter, r *http.Request) (string, bool) {
50 r = r.Clone(ctx)

Callers 1

newRejectAuthFromURLFunction · 0.85

Calls 1

GetMethod · 0.45

Tested by

no test coverage detected