-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp.go
More file actions
37 lines (31 loc) · 1.01 KB
/
http.go
File metadata and controls
37 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package jrm1
import (
"net/http"
mime "github.com/vault-thirteen/auxie/MIME"
h "github.com/vault-thirteen/auxie/header"
hh "github.com/vault-thirteen/auxie/http-helper"
)
// checkHttpRequest checks the HTTP request and responds on error.
// If the request is correct and ready to be processed, 'True' is returned.
// When 'False' is returned, the caller must stop serving the request.
func checkHttpRequest(rw http.ResponseWriter, req *http.Request) (proceed bool) {
// 1. Check HTTP method.
if req.Method != http.MethodPost {
rw.WriteHeader(http.StatusMethodNotAllowed)
return false
}
// 2. Check HTTP content type.
ctype, err := hh.GetSingleHttpHeader(req, h.HttpHeaderContentType)
if (err != nil) || (ctype != mime.TypeApplicationJson) {
rw.WriteHeader(http.StatusUnsupportedMediaType)
return false
}
// 3. Check accepted HTTP content type.
var ok bool
ok, err = hh.CheckBrowserSupportForJson(req)
if (err != nil) || !ok {
rw.WriteHeader(http.StatusNotAcceptable)
return false
}
return true
}