isAjax checks if a request is an ajax request
(req *http.Request)
| 1317 | |
| 1318 | // isAjax checks if a request is an ajax request |
| 1319 | func isAjax(req *http.Request) bool { |
| 1320 | acceptValues := req.Header.Values("Accept") |
| 1321 | const ajaxReq = applicationJSON |
| 1322 | // Iterate over multiple Accept headers, i.e. |
| 1323 | // Accept: application/json |
| 1324 | // Accept: text/plain |
| 1325 | for _, mimeTypes := range acceptValues { |
| 1326 | // Iterate over multiple mimetypes in a single header, i.e. |
| 1327 | // Accept: application/json, text/plain, */* |
| 1328 | for _, mimeType := range strings.Split(mimeTypes, ",") { |
| 1329 | mimeType = strings.TrimSpace(mimeType) |
| 1330 | if mimeType == ajaxReq { |
| 1331 | return true |
| 1332 | } |
| 1333 | } |
| 1334 | } |
| 1335 | return false |
| 1336 | } |
| 1337 | |
| 1338 | // errorJSON returns the error code with an application/json mime type |
| 1339 | func (p *OAuthProxy) errorJSON(rw http.ResponseWriter, code int) { |