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

Method Validate

auth/rejectstatic.go:49–76  ·  view source on GitHub ↗
(ctx context.Context, w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

47}
48
49func (a *StaticRejectAuth) Validate(ctx context.Context, w http.ResponseWriter, r *http.Request) (string, bool) {
50 if a.hdrs != "" {
51 f, err := os.Open(a.hdrs)
52 if err != nil {
53 a.logger.Error("unable to open file with auth rejection headers: %v", err)
54 } else {
55 defer f.Close()
56 if err := applyHeaders(f, w.Header()); err != nil {
57 a.logger.Error("header processing failed: %v", err)
58 }
59
60 }
61 }
62 w.WriteHeader(a.code)
63 if a.body != "" {
64 f, err := os.Open(a.body)
65 if err != nil {
66 a.logger.Error("unable to open file with auth rejection body: %v", err)
67 return "", false
68 }
69 defer f.Close()
70 _, err = io.Copy(w, f)
71 if err != nil {
72 a.logger.Debug("auth rejection body write failed: %v", err)
73 }
74 }
75 return "", false
76}
77
78func applyHeaders(r io.Reader, h http.Header) error {
79 scanner := bufio.NewScanner(r)

Callers

nothing calls this directly

Calls 4

applyHeadersFunction · 0.85
CloseMethod · 0.65
ErrorMethod · 0.45
DebugMethod · 0.45

Tested by

no test coverage detected