Skip to content

Commit

Permalink
feat(proxy): supports custom proxy headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Noooste committed Aug 13, 2024
1 parent 6810924 commit d98e37b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions connection_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ type proxyDialer struct {

tr *http2.Transport
ForceHTTP2 bool

sess *Session
}

const (
Expand Down Expand Up @@ -74,6 +76,7 @@ func (s *Session) assignProxy(proxy string) error {
s.ProxyDialer = &proxyDialer{
ProxyURL: parsed,
DefaultHeader: make(http.Header),
sess: s,
}

if parsed.User != nil {
Expand Down Expand Up @@ -122,6 +125,16 @@ func (c *proxyDialer) DialContext(ctx context.Context, userAgent, network, addre
req.Header[k] = v
}

for k, v := range c.sess.ProxyHeader {
if k == http.HeaderOrderKey {
for _, vv := range v {
req.Header[http.HeaderOrderKey] = append(req.Header[http.HeaderOrderKey], strings.ToLower(vv))
}
} else {
req.Header[k] = v
}
}

if ctxHeader, ctxHasHeader := ctx.Value(ContextKeyHeader{}).(http.Header); ctxHasHeader {
for k, v := range ctxHeader {
req.Header[k] = v
Expand Down
10 changes: 9 additions & 1 deletion structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Session struct {

// Maximum number of redirects to follow.
MaxRedirects uint

// Maximum time to wait for request to complete.
TimeOut time.Duration

Expand Down Expand Up @@ -104,14 +105,22 @@ type Session struct {
// Deprecated: This field is ignored as pin verification is always true.
// To disable pin verification, use InsecureSkipVerify.
VerifyPins bool

// If true, server's certificate is not verified (insecure: this may facilitate attack from middleman).
InsecureSkipVerify bool

// Headers for User-Agent and Sec-Ch-Ua, respectively.
UserAgent string

// HeaderPriority specifies the priority of the request's headers.
// As this information is not included in the Akamai fingerprint, you may have to specify it manually.
// Note that you can also specify the browser in the session so that this is done automatically.
HeaderPriority *http2.PriorityParam

// ProxyHeader defines the headers used for the CONNECT method to the proxy,
// you may define the order with the http.HeaderOrderKey
ProxyHeader http.Header

proxyConnected bool

dump bool
Expand All @@ -121,7 +130,6 @@ type Session struct {
logging bool
loggingIgnore []*regexp.Regexp

// Context for cancellable and timeout operations.
ctx context.Context

mu *sync.Mutex
Expand Down

0 comments on commit d98e37b

Please sign in to comment.