@@ -11,6 +11,17 @@ import (
11
11
// ErrServerSupport indicates whether the server supports HTTP/2 or not.
12
12
var ErrServerSupport = errors .New ("server doesn't support HTTP/2" )
13
13
14
+ // clientAdapter adapts a Client.Do method to implement fasthttp.RoundTripper
15
+ type clientAdapter struct {
16
+ client * Client
17
+ }
18
+
19
+ // RoundTrip implements fasthttp.RoundTripper by calling the wrapped client's Do method
20
+ func (ca * clientAdapter ) RoundTrip (hc * fasthttp.HostClient , req * fasthttp.Request , resp * fasthttp.Response ) (retry bool , err error ) {
21
+ err = ca .client .Do (req , resp )
22
+ return false , err
23
+ }
24
+
14
25
func configureDialer (d * Dialer ) {
15
26
if d .TLSConfig == nil {
16
27
d .TLSConfig = & tls.Config {
@@ -67,7 +78,7 @@ func ConfigureClient(c *fasthttp.HostClient, opts ClientOpts) error {
67
78
c .IsTLS = true
68
79
c .TLSConfig = d .TLSConfig
69
80
70
- c .Transport = cl
81
+ c .Transport = & clientAdapter { client : cl }
71
82
72
83
return nil
73
84
}
@@ -79,14 +90,14 @@ func ConfigureClient(c *fasthttp.HostClient, opts ClientOpts) error {
79
90
// Future implementations may support HTTP/2 through plain TCP.
80
91
//
81
92
// This package currently supports the following fasthttp.Server settings:
82
- // - Handler: Obviously, the handler is taken from the Server.
83
- // - ReadTimeout: Will cancel a stream if the client takes more than ReadTimeout
84
- // to send a request. This option NEVER closes the connection.
85
- // - IdleTimeout: Will close the connection if the client doesn't send a request
86
- // within the IdleTimeout. This option ignores any PING/PONG mechanism.
87
- // To disable the option you can set it to zero. No value is taken by default,
88
- // which means that by default ALL connections are open until either endpoint
89
- // closes the connection.
93
+ // - Handler: Obviously, the handler is taken from the Server.
94
+ // - ReadTimeout: Will cancel a stream if the client takes more than ReadTimeout
95
+ // to send a request. This option NEVER closes the connection.
96
+ // - IdleTimeout: Will close the connection if the client doesn't send a request
97
+ // within the IdleTimeout. This option ignores any PING/PONG mechanism.
98
+ // To disable the option you can set it to zero. No value is taken by default,
99
+ // which means that by default ALL connections are open until either endpoint
100
+ // closes the connection.
90
101
func ConfigureServer (s * fasthttp.Server , cnf ServerConfig ) * Server {
91
102
cnf .defaults ()
92
103
@@ -113,4 +124,4 @@ func ConfigureServerAndConfig(s *fasthttp.Server, tlsConfig *tls.Config) *Server
113
124
return s2
114
125
}
115
126
116
- var ErrNotAvailableStreams = errors .New ("ran out of available streams" )
127
+ var ErrNotAvailableStreams = errors .New ("ran out of available streams" )
0 commit comments