Skip to content

Commit fdccbe3

Browse files
committed
WIP
1 parent fe9e9d9 commit fdccbe3

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

auth/auth.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func NewAuth(paramstr string, logger *clog.CondLogger) (Auth, error) {
3636
return NewRedisAuth(url, true, logger)
3737
case "none":
3838
return NoAuth{}, nil
39+
case "reject-http", "reject-https":
40+
return NewRejectHTTPAuth(url, logger)
3941
default:
4042
return nil, errors.New("Unknown auth scheme")
4143
}

auth/reject.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package auth
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"net/http/httputil"
7+
"net/url"
8+
"strings"
9+
10+
clog "github.com/SenseUnit/dumbproxy/log"
11+
)
12+
13+
type RejectHTTPAuth struct {
14+
proxy *httputil.ReverseProxy
15+
}
16+
17+
func NewRejectHTTPAuth(u *url.URL, logger *clog.CondLogger) (*RejectHTTPAuth, error) {
18+
target := *u
19+
scheme, _ := strings.CutPrefix(strings.ToLower(u.Scheme), "reject-")
20+
target.Scheme = scheme
21+
return &RejectHTTPAuth{
22+
proxy: &httputil.ReverseProxy{
23+
Rewrite: func(r *httputil.ProxyRequest) {
24+
// r.SetURL(&target)
25+
// r.Out.Host = r.In.Host // if desired
26+
r.Out.URL = &target
27+
r.Out.Host = ""
28+
},
29+
},
30+
}, nil
31+
}
32+
33+
func (a *RejectHTTPAuth) Validate(ctx context.Context, w http.ResponseWriter, r *http.Request) (string, bool) {
34+
r = r.Clone(ctx)
35+
a.proxy.ServeHTTP(w, r)
36+
return "", false
37+
}
38+
39+
func (_ *RejectHTTPAuth) Valid(_, _, _ string) bool {
40+
return false
41+
}
42+
43+
func (_ *RejectHTTPAuth) Stop() {}

0 commit comments

Comments
 (0)