diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-16 15:48:52 +0100 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2023-02-16 15:52:05 +0100 |
| commit | 807140ce43584e9612f7b5890b13d751247f8e6e (patch) | |
| tree | 08e05fd79078f5093bc7aea68557b212bb5c1bfa /internal/test/handler.go | |
| parent | f718788442682f87e2fd1b6067f6062bade52d52 (diff) | |
Server: Validate endpoints
This commit validates the server endpoints by checking the Host and
scheme of each URL to check if they match eachother. This is to
prevent further mixup attacks
Diffstat (limited to 'internal/test/handler.go')
| -rw-r--r-- | internal/test/handler.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/internal/test/handler.go b/internal/test/handler.go new file mode 100644 index 0000000..5c02629 --- /dev/null +++ b/internal/test/handler.go @@ -0,0 +1,25 @@ +package test + +import ( + "net/http" + "sync" +) + +// HandlerSet is a struct with a mutex that allows us to swap handlers while a test server is running +type HandlerSet struct { + mu sync.Mutex + handler http.Handler +} + +func (hs *HandlerSet) SetHandler(handler http.Handler) { + hs.mu.Lock() + hs.handler = handler + hs.mu.Unlock() +} + +func (hs *HandlerSet) ServeHTTP(w http.ResponseWriter, r *http.Request) { + hs.mu.Lock() + handler := hs.handler + hs.mu.Unlock() + handler.ServeHTTP(w, r) +} |
