45 lines · 1.2 KB · Go
RawDownload
package helps import (	"context"	"io"	"net/http"	"strings"	"testing") type utlsClientRoundTripFunc func(*http.Request) (*http.Response, error) func (f utlsClientRoundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {	return f(req)} func TestNewUtlsHTTPClientUsesContextRoundTripperForProtectedHost(t *testing.T) {	t.Parallel() 	called := false	ctx := context.WithValue(context.Background(), "cliproxy.roundtripper", utlsClientRoundTripFunc(func(req *http.Request) (*http.Response, error) {		called = true		if req.URL.Hostname() != "chatgpt.com" {			t.Fatalf("hostname = %q, want chatgpt.com", req.URL.Hostname())		}		return &http.Response{			StatusCode: http.StatusOK,			Header:     make(http.Header),			Body:       io.NopCloser(strings.NewReader("{}")),			Request:    req,		}, nil	})) 	client := NewUtlsHTTPClient(ctx, nil, nil, 0)	resp, err := client.Get("https://chatgpt.com/backend-api/codex/responses")	if err != nil {		t.Fatalf("client.Get returned error: %v", err)	}	if errClose := resp.Body.Close(); errClose != nil {		t.Fatalf("response body close returned error: %v", errClose)	}	if !called {		t.Fatal("expected context RoundTripper to handle protected host request")	}}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t