MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / isAjax

Function isAjax

oauthproxy.go:1319–1336  ·  view source on GitHub ↗

isAjax checks if a request is an ajax request

(req *http.Request)

Source from the content-addressed store, hash-verified

1317
1318// isAjax checks if a request is an ajax request
1319func 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
1339func (p *OAuthProxy) errorJSON(rw http.ResponseWriter, code int) {

Callers 1

ProxyMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected