@@ -749,6 +749,18 @@ func (h *Host) RoundTrip(r *http.Request) (*http.Response, error) {
749
749
switch r .URL .Scheme {
750
750
case "http" , "https" :
751
751
h .initDefaultRT ()
752
+ if r .Host == "" {
753
+ r .Host = r .URL .Host
754
+ }
755
+ if h .ClientPeerIDAuth != nil && h .ClientPeerIDAuth .HasToken (r .Host ) {
756
+ serverID , resp , err := h .ClientPeerIDAuth .AuthenticateWithRoundTripper (h .DefaultClientRoundTripper , r )
757
+ if err != nil {
758
+ return nil , err
759
+ }
760
+ ctxWithServerID := context .WithValue (r .Context (), serverPeerIDContextKey {}, serverID )
761
+ resp .Request = resp .Request .WithContext (ctxWithServerID )
762
+ return resp , nil
763
+ }
752
764
return h .DefaultClientRoundTripper .RoundTrip (r )
753
765
case "multiaddr" :
754
766
break
@@ -780,7 +792,12 @@ func (h *Host) RoundTrip(r *http.Request) (*http.Response, error) {
780
792
781
793
h .initDefaultRT ()
782
794
rt := h .DefaultClientRoundTripper
783
- if parsed .sni != parsed .host {
795
+ sni := parsed .sni
796
+ if sni == "" {
797
+ sni = parsed .host
798
+ }
799
+
800
+ if sni != parsed .host {
784
801
// We have a different host and SNI (e.g. using an IP address but specifying a SNI)
785
802
// We need to make our own transport to support this.
786
803
//
@@ -803,6 +820,8 @@ func (h *Host) RoundTrip(r *http.Request) (*http.Response, error) {
803
820
}
804
821
805
822
serverID , resp , err := h .ClientPeerIDAuth .AuthenticateWithRoundTripper (rt , r )
823
+ // c := http.Client{Transport: rt}
824
+ // serverID, resp, err := h.ClientPeerIDAuth.AuthenticatedDo(&c, r)
806
825
if err != nil {
807
826
return nil , err
808
827
}
@@ -1165,6 +1184,9 @@ func connectionCloseHeaderMiddleware(next http.Handler) http.Handler {
1165
1184
// maybeDecorateContextWithAuth decorates the request context with
1166
1185
// authentication information if serverAuth is provided.
1167
1186
func maybeDecorateContextWithAuthMiddleware (serverAuth * httpauth.ServerPeerIDAuth , next http.Handler ) http.Handler {
1187
+ if next == nil {
1188
+ return nil
1189
+ }
1168
1190
if serverAuth == nil {
1169
1191
return next
1170
1192
}
0 commit comments