Skip to content

Commit

Permalink
Handle Basic Auth before HTTP RoundTrip
Browse files Browse the repository at this point in the history
  • Loading branch information
dyhkwong committed Jun 13, 2024
1 parent e29ba5d commit 74908ff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions quic/transport_http3.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (t *HTTP3Transport) Exchange(ctx context.Context, message *mDNS.Msg) (*mDNS
}
request.Header.Set("Content-Type", dns.MimeType)
request.Header.Set("Accept", dns.MimeType)
if u, err := url.Parse(t.destination); err == nil && u.User != nil {
password, _ := u.User.Password()
request.SetBasicAuth(u.User.Username(), password)
}
response, err := t.transport.RoundTrip(request)
requestBuffer.Release()
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions transport_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net"
"net/http"
"net/netip"
"net/url"
"os"

"github.com/sagernet/sing/common/buf"
Expand Down Expand Up @@ -88,6 +89,10 @@ func (t *HTTPSTransport) Exchange(ctx context.Context, message *dns.Msg) (*dns.M
}
request.Header.Set("Content-Type", MimeType)
request.Header.Set("Accept", MimeType)
if u, err := url.Parse(t.destination); err == nil && u.User != nil {
password, _ := u.User.Password()
request.SetBasicAuth(u.User.Username(), password)
}
response, err := t.transport.RoundTrip(request)
requestBuffer.Release()
if err != nil {
Expand Down

0 comments on commit 74908ff

Please sign in to comment.