You've already forked oauth2-proxy
							
							
				mirror of
				https://github.com/oauth2-proxy/oauth2-proxy.git
				synced 2025-10-30 23:47:52 +02:00 
			
		
		
		
	Merge pull request #989 from rassie/master
Adapt isAjax to support mimetype lists
This commit is contained in:
		| @@ -100,6 +100,7 @@ | ||||
| - [#750](https://github.com/oauth2-proxy/oauth2-proxy/pull/750) ci: Migrate to Github Actions (@shinebayar-g) | ||||
| - [#829](https://github.com/oauth2-proxy/oauth2-proxy/pull/820) Rename test directory to testdata (@johejo) | ||||
| - [#819](https://github.com/oauth2-proxy/oauth2-proxy/pull/819) Improve CI (@johejo) | ||||
| - [#989](https://github.com/oauth2-proxy/oauth2-proxy/pull/989) Adapt isAjax to support mimetype lists (@rassie) | ||||
|  | ||||
| # v6.1.1 | ||||
|  | ||||
|   | ||||
| @@ -1111,9 +1111,17 @@ func (p *OAuthProxy) addHeadersForProxying(rw http.ResponseWriter, req *http.Req | ||||
| func isAjax(req *http.Request) bool { | ||||
| 	acceptValues := req.Header.Values("Accept") | ||||
| 	const ajaxReq = applicationJSON | ||||
| 	for _, v := range acceptValues { | ||||
| 		if v == ajaxReq { | ||||
| 			return true | ||||
| 	// Iterate over multiple Accept headers, i.e. | ||||
| 	// Accept: application/json | ||||
| 	// Accept: text/plain | ||||
| 	for _, mimeTypes := range acceptValues { | ||||
| 		// Iterate over multiple mimetypes in a single header, i.e. | ||||
| 		// Accept: application/json, text/plain, */* | ||||
| 		for _, mimeType := range strings.Split(mimeTypes, ",") { | ||||
| 			mimeType = strings.TrimSpace(mimeType) | ||||
| 			if mimeType == ajaxReq { | ||||
| 				return true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return false | ||||
|   | ||||
| @@ -1970,6 +1970,13 @@ func TestAjaxUnauthorizedRequest2(t *testing.T) { | ||||
| 	testAjaxUnauthorizedRequest(t, header) | ||||
| } | ||||
|  | ||||
| func TestAjaxUnauthorizedRequestAccept1(t *testing.T) { | ||||
| 	header := make(http.Header) | ||||
| 	header.Add("Accept", "application/json, text/plain, */*") | ||||
|  | ||||
| 	testAjaxUnauthorizedRequest(t, header) | ||||
| } | ||||
|  | ||||
| func TestAjaxForbiddendRequest(t *testing.T) { | ||||
| 	test, err := newAjaxRequestTest() | ||||
| 	if err != nil { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user