Common functionality for these request handlers. Returns true if the request is completely handled here and nothing further needs to be done.
(w http.ResponseWriter, r *http.Request)
| 42 | // Common functionality for these request handlers. Returns true if the request is completely |
| 43 | // handled here and nothing further needs to be done. |
| 44 | func commonHandler(w http.ResponseWriter, r *http.Request) bool { |
| 45 | // Do these requests really need CORS headers? Doesn't seem like it, but they are probably |
| 46 | // harmless aside from the extra size they add to each response. |
| 47 | x.AddCorsHeaders(w) |
| 48 | w.Header().Set("Content-Type", "application/json") |
| 49 | |
| 50 | if r.Method == "OPTIONS" { |
| 51 | return true |
| 52 | } else if !allowed(r.Method) { |
| 53 | w.WriteHeader(http.StatusBadRequest) |
| 54 | x.SetStatus(w, x.ErrorInvalidMethod, "Invalid method") |
| 55 | return true |
| 56 | } |
| 57 | |
| 58 | return false |
| 59 | } |
| 60 | |
| 61 | // Read request body, transparently decompressing if necessary. Return nil on error. |
| 62 | func readRequest(w http.ResponseWriter, r *http.Request) []byte { |
no test coverage detected