You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-07-15 01:44:22 +02:00
Support context in providers (#519)
Co-authored-by: Henry Jenkins <henry@henryjenkins.name>
This commit is contained in:
committed by
Henry Jenkins
parent
53d8e99f05
commit
e642daef4e
@ -1,6 +1,7 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
@ -62,8 +63,8 @@ func RequestJSON(req *http.Request, v interface{}) error {
|
||||
}
|
||||
|
||||
// RequestUnparsedResponse performs a GET and returns the raw response object
|
||||
func RequestUnparsedResponse(url string, header http.Header) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
func RequestUnparsedResponse(ctx context.Context, url string, header http.Header) (resp *http.Response, err error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error performing get request: %w", err)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@ -87,7 +88,7 @@ func TestRequestUnparsedResponseUsingAccessTokenParameter(t *testing.T) {
|
||||
defer backend.Close()
|
||||
|
||||
response, err := RequestUnparsedResponse(
|
||||
backend.URL+"?access_token=my_token", nil)
|
||||
context.Background(), backend.URL+"?access_token=my_token", nil)
|
||||
assert.Equal(t, nil, err)
|
||||
defer response.Body.Close()
|
||||
|
||||
@ -103,7 +104,7 @@ func TestRequestUnparsedResponseUsingAccessTokenParameterFailedResponse(t *testi
|
||||
backend.Close()
|
||||
|
||||
response, err := RequestUnparsedResponse(
|
||||
backend.URL+"?access_token=my_token", nil)
|
||||
context.Background(), backend.URL+"?access_token=my_token", nil)
|
||||
assert.NotEqual(t, nil, err)
|
||||
assert.Equal(t, (*http.Response)(nil), response)
|
||||
}
|
||||
@ -123,7 +124,7 @@ func TestRequestUnparsedResponseUsingHeaders(t *testing.T) {
|
||||
|
||||
headers := make(http.Header)
|
||||
headers.Set("Auth", "my_token")
|
||||
response, err := RequestUnparsedResponse(backend.URL, headers)
|
||||
response, err := RequestUnparsedResponse(context.Background(), backend.URL, headers)
|
||||
assert.Equal(t, nil, err)
|
||||
defer response.Body.Close()
|
||||
|
||||
|
Reference in New Issue
Block a user