feat: add custom header support to PHT protocol
- Add Header field to PHT Client and clientConn structs - Support custom headers in authorize, push, and pull requests - Add metadata parsing for header configuration as map[string]string - Enables PHT usage with header-based authentication (e.g., Cloudflare Access) Backwards compatible - headers are optional.
This commit is contained in:
committed by
ginuerzh
parent
cd7bf9521f
commit
96f35bd7aa
@@ -21,6 +21,7 @@ type Client struct {
|
||||
PushPath string
|
||||
PullPath string
|
||||
TLSEnabled bool
|
||||
Header http.Header
|
||||
Logger logger.Logger
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ func (c *Client) Dial(ctx context.Context, addr string) (net.Conn, error) {
|
||||
|
||||
cn := &clientConn{
|
||||
client: c.Client,
|
||||
header: c.Header,
|
||||
rxc: make(chan []byte, 128),
|
||||
closed: make(chan struct{}),
|
||||
localAddr: &net.TCPAddr{},
|
||||
@@ -74,6 +76,15 @@ func (c *Client) authorize(ctx context.Context, addr string) (token string, err
|
||||
return
|
||||
}
|
||||
|
||||
// Inject custom headers
|
||||
if c.Header != nil {
|
||||
for k, values := range c.Header {
|
||||
for _, v := range values {
|
||||
r.Header.Add(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if c.Logger.IsLevelEnabled(logger.TraceLevel) {
|
||||
dump, _ := httputil.DumpRequest(r, false)
|
||||
c.Logger.Trace(string(dump))
|
||||
|
||||
Reference in New Issue
Block a user