Skip to content

Commit 968c885

Browse files
committed
internal/web/proxy: handle unsupported HTTP method
1 parent f992754 commit 968c885

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

internal/web/proxy.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ const (
2525
maxBodyBytes = 32 * 1024 * 1024
2626
)
2727

28+
var djangoHTTPMethods = map[string]struct{}{
29+
http.MethodGet: {},
30+
http.MethodHead: {},
31+
http.MethodPost: {},
32+
http.MethodPut: {},
33+
http.MethodPatch: {},
34+
http.MethodDelete: {},
35+
http.MethodOptions: {},
36+
http.MethodTrace: {},
37+
}
38+
39+
func handleUnsupportedHTTPMethod(rw http.ResponseWriter, r *http.Request) bool {
40+
if _, ok := djangoHTTPMethods[r.Method]; ok {
41+
return false
42+
}
43+
http.Error(rw, "Unsupported HTTP method.", http.StatusNotImplemented)
44+
return true
45+
}
46+
2847
func (ws *WebServer) configureProxy() {
2948
// Reverse proxy to the application server
3049
director := func(req *http.Request) {
@@ -84,6 +103,10 @@ func (ws *WebServer) configureProxy() {
84103
return
85104
}
86105

106+
if handleUnsupportedHTTPMethod(rw, r) {
107+
return
108+
}
109+
87110
r.Body = http.MaxBytesReader(rw, r.Body, maxBodyBytes)
88111
rp.ServeHTTP(rw, r)
89112

0 commit comments

Comments
 (0)