Skip to content

Commit bd43e91

Browse files
[+] fix: concurrent HTTP requests (#107)
* [+] fix: concurrent HTTP requests * chore: Updated coverage badge. --------- Co-authored-by: GitHub Action <[email protected]>
1 parent 8d108b4 commit bd43e91

File tree

4 files changed

+18
-22
lines changed

4 files changed

+18
-22
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AzureTLS Client
22
[![GoDoc](https://godoc.org/github.com/Noooste/azuretls-client?status.svg)](https://godoc.org/github.com/Noooste/azuretls-client)
3-
![Coverage](https://img.shields.io/badge/Coverage-77.8%25-brightgreen)
3+
![Coverage](https://img.shields.io/badge/Coverage-77.6%25-brightgreen)
44
[![build](https://github.com/Noooste/azuretls-client/actions/workflows/push.yml/badge.svg)](https://github.com/Noooste/azuretls-client/actions/workflows/push.yml)
55
[![Go Report Card](https://goreportcard.com/badge/Noooste/azuretls-client)](https://goreportcard.com/report/Noooste/azuretls-client)
66
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Noooste/azuretls-client/blob/master/LICENSE)

connection.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,9 @@ func (s *Session) initConn(req *Request) (conn *Conn, err error) {
316316
return nil, err
317317
}
318318
} else {
319-
if conn.Conn, err = (&net.Dialer{Timeout: conn.TimeOut}).DialContext(s.ctx, "tcp", host); err != nil {
319+
if conn.Conn, err = (&net.Dialer{
320+
Timeout: conn.TimeOut,
321+
}).DialContext(s.ctx, "tcp", host); err != nil {
320322
return nil, err
321323
}
322324
}

test/connection_test.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ func concurrency(session *azuretls.Session, wg *sync.WaitGroup, ok *int64) bool
9090
fmt.Println(err2)
9191
return false
9292
}
93+
94+
_, err2 = session.Get("http://example.com/")
95+
96+
if err2 != nil {
97+
fmt.Println(err2)
98+
return false
99+
}
93100
}
94101

95102
atomic.AddInt64(ok, 1)
@@ -107,7 +114,6 @@ func TestHighConcurrency(t *testing.T) {
107114

108115
wait.Add(int(count))
109116

110-
var err error
111117
var ok = new(int64)
112118

113119
var i int64
@@ -118,12 +124,7 @@ func TestHighConcurrency(t *testing.T) {
118124

119125
wait.Wait()
120126

121-
if err != nil {
122-
t.Error("TestHighConcurrency failed, expected: ", count, ", got: ", ok)
123-
t.Fatal(err)
124-
}
125-
126127
if atomic.LoadInt64(ok) < count-1 { //~1 request can fail
127-
t.Fatal("TestHighConcurrency failed, expected: ", count, ", got: ", ok)
128+
t.Fatal("TestHighConcurrency failed, expected: ", count, ", got: ", *ok)
128129
}
129130
}

transport.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package azuretls
22

33
import (
4-
"context"
54
http "github.com/Noooste/fhttp"
65
"github.com/Noooste/fhttp/http2"
7-
"net"
6+
"net/url"
87
)
98

109
func (s *Session) initTransport(browser string) (err error) {
@@ -28,17 +27,11 @@ func (s *Session) initHTTP1() {
2827
s.Transport = &http.Transport{
2928
TLSHandshakeTimeout: s.TimeOut,
3029
ResponseHeaderTimeout: s.TimeOut,
31-
DialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
32-
s.Connections.mu.RLock()
33-
defer s.Connections.mu.RUnlock()
34-
rc := s.Connections.hosts[addr]
35-
return rc.TLS, nil
36-
},
37-
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
38-
s.Connections.mu.RLock()
39-
defer s.Connections.mu.RUnlock()
40-
rc := s.Connections.hosts[addr]
41-
return rc.Conn, nil
30+
Proxy: func(req *http.Request) (*url.URL, error) {
31+
if s.ProxyDialer == nil {
32+
return nil, nil
33+
}
34+
return s.ProxyDialer.ProxyURL, nil
4235
},
4336
}
4437
}

0 commit comments

Comments
 (0)