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:
Vasileios Papadimas
2026-01-16 14:35:48 +02:00
committed by ginuerzh
parent cd7bf9521f
commit 96f35bd7aa
4 changed files with 44 additions and 0 deletions
+1
View File
@@ -109,6 +109,7 @@ func (d *phtDialer) Dial(ctx context.Context, addr string, opts ...dialer.DialOp
PushPath: d.md.pushPath,
PullPath: d.md.pullPath,
TLSEnabled: d.tlsEnabled,
Header: d.md.header,
Logger: d.options.Logger,
}
d.clients[addr] = client
+13
View File
@@ -1,6 +1,7 @@
package pht
import (
"net/http"
"strings"
mdata "github.com/go-gost/core/metadata"
@@ -19,6 +20,7 @@ type metadata struct {
pushPath string
pullPath string
host string
header http.Header
}
func (d *phtDialer) parseMetadata(md mdata.Metadata) (err error) {
@@ -27,6 +29,7 @@ func (d *phtDialer) parseMetadata(md mdata.Metadata) (err error) {
pushPath = "pushPath"
pullPath = "pullPath"
host = "host"
header = "header"
)
d.md.authorizePath = mdutil.GetString(md, authorizePath)
@@ -43,5 +46,15 @@ func (d *phtDialer) parseMetadata(md mdata.Metadata) (err error) {
}
d.md.host = mdutil.GetString(md, host)
// Parse custom headers
if m := mdutil.GetStringMapString(md, header); len(m) > 0 {
h := http.Header{}
for k, v := range m {
h.Add(k, v)
}
d.md.header = h
}
return
}