@@ -96,8 +96,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
96
96
}()
97
97
98
98
if ! allowOrigin (r , h .cfg ) || ! allowReferer (r , h .cfg ) {
99
- w .WriteHeader (http .StatusForbidden )
100
- w .Write ([]byte ("403 - Forbidden" ))
99
+ http .Error (w , "403 - Forbidden" , http .StatusForbidden )
101
100
log .Warningf ("API blocked request to %s. (possible CSRF)" , r .URL )
102
101
return
103
102
}
@@ -122,12 +121,12 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
122
121
123
122
req , err := parseRequest (r , h .root )
124
123
if err != nil {
124
+ status := http .StatusBadRequest
125
125
if err == ErrNotFound {
126
- w .WriteHeader (http .StatusNotFound )
127
- } else {
128
- w .WriteHeader (http .StatusBadRequest )
126
+ status = http .StatusNotFound
129
127
}
130
- w .Write ([]byte (err .Error ()))
128
+
129
+ http .Error (w , err .Error (), status )
131
130
return
132
131
}
133
132
@@ -146,8 +145,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
146
145
147
146
re , err := NewResponseEmitter (w , r .Method , req , withRequestBodyEOFChan (bodyEOFChan ))
148
147
if err != nil {
149
- w .WriteHeader (http .StatusBadRequest )
150
- w .Write ([]byte (err .Error ()))
148
+ http .Error (w , err .Error (), http .StatusBadRequest )
151
149
return
152
150
}
153
151
0 commit comments