<commit_before>package oidc

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"mime"
	"net/http"
	"net/url"
	"strings"
	"time"

	jose "gopkg.in/square/go-jose.v2"
)

const (
	// ScopeOpenID is the mandatory scope for all OpenID Connect OAuth2 requests.
	ScopeOpenID        = "openid"
	ScopeOfflineAccess = "offline_access"
	ScopeEmail         = "email"
	ScopeProfile       = "profile"

	GrantTypeAuthCode     = "authorization_code"
	GrantTypeRefreshToken = "refresh_token"

	ResponseTypeCode    = "code"     // Authorization Code flow
	ResponseTypeToken   = "token"    // Implicit flow for frontend apps.
	ResponseTypeIDToken = "id_token" // ID Token in url fragment

	DiscoveryEndpoint = "/.well-known/openid-configuration"
)

// HTTPClientCtxKey is Context key which is used to fetch custom HTTP.Client.
// Used to pass special HTTP client (e.g with non-default timeout) or for tests.
var HTTPClientCtxKey struct{}

// doRequest performs HTTP request using Default client or client given by context like this:
//
//     context.WithValue(ctx, oidc.HTTPClientCtxKey, client)
//
func doRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
	// Clone transport before using it. We don't want to depend on the default one.
	clonedTransport := &(*http.DefaultTransport.(*http.Transport))
	client := &http.Client{
		Transport: clonedTransport,
	}
	if c, ok := ctx.Value(HTTPClientCtxKey).(*http.Client); ok {
		client = c<commit_msg>Use new transport instead of copying default one (#9)<commit_after>package oidc

import (
	"bytes"
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"io"
	"io/ioutil"
	"mime"
	"net"
	"net/http"
	"net/url"
	"strings"
	"time"

	jose "gopkg.in/square/go-jose.v2"
)

const (
	// ScopeOpenID is the mandatory scope for all OpenID Connect OAuth2 requests.
	ScopeOpenID        = "openid"
	ScopeOfflineAccess = "offline_access"
	ScopeEmail         = "email"
	ScopeProfile       = "profile"

	GrantTypeAuthCode     = "authorization_code"
	GrantTypeRefreshToken = "refresh_token"

	ResponseTypeCode    = "code"     // Authorization Code flow
	ResponseTypeToken   = "token"    // Implicit flow for frontend apps.
	ResponseTypeIDToken = "id_token" // ID Token in url fragment

	DiscoveryEndpoint = "/.well-known/openid-configuration"
)

// HTTPClientCtxKey is Context key which is used to fetch custom HTTP.Client.
// Used to pass special HTTP client (e.g with non-default timeout) or for tests.
var HTTPClientCtxKey struct{}

// doRequest performs HTTP request using our default client or client given by context like this:
//
//     context.WithValue(ctx, oidc.HTTPClientCtxKey, client)
//
func doRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
	// Create new transport before using it with exactly the same params as default one. Don't use it directly, because
	// we don't want to depend on the default one.
	newTransport := &http.Transport{
		Proxy: http.ProxyFromEnvironment,
		DialContext: (&net.Dialer{
			Timeout:   30 * time.Second,
			KeepAlive: 30 * time.Second,
			DualStack: true,
		}).DialContext,
		MaxIdleConns:          100,
		IdleConnTimeout:       90 * time.Second,
		TLSHandshakeTimeout:   10 * time.Second,
		ExpectContinueTimeout: 1 * time.Second,
	}
	client := &http.Client{
		Transport: newTransport,
	}
	if c, ok := ctx.Value(HTTPClientCtxKey).(*http.Client); ok {
		client = c
{'fraction_non_alphanumeric': 0.10924617196702002, 'fraction_numerical': 0.005005889281507656, 'mean_word_length': 3.6598079561042525, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4275580', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1107, 'n_words': 327}