Skip to content

Commit

Permalink
http/2 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarazzutti committed Dec 9, 2021
1 parent ee0b8de commit da8144b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 32 deletions.
2 changes: 2 additions & 0 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ type Config struct {
Parameters []Parameter
IgnoreServerErrors bool
ExtraParam bool
Http2 bool
Http2z bool
}
4 changes: 2 additions & 2 deletions app/httpping.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func HTTPPing(config *Config) {
if config.LogLevel == 1 {
fmt.Printf("%4d: code=%d size=%d time=%.3f ms\n", attempts, measure.StatusCode, measure.Bytes, float64(measure.Duration.Nanoseconds())/1e6)
} else if config.LogLevel == 2 {
fmt.Printf("%4d: code=%d conn-reused=%t size=%d in=%d out=%d time=%.3f ms\n", attempts, measure.StatusCode, measure.SocketReused, measure.Bytes, measure.InBytes, measure.OutBytes, float64(measure.Duration.Nanoseconds())/1e6)
fmt.Printf("%4d: code=%d proto=%s conn-reused=%t size=%d in=%d out=%d time=%.3f ms\n", attempts, measure.StatusCode, measure.Proto, measure.SocketReused, measure.Bytes, measure.InBytes, measure.OutBytes, float64(measure.Duration.Nanoseconds())/1e6)
}
latencies = append(latencies, measure.Duration)
} else {
Expand Down Expand Up @@ -70,6 +70,6 @@ func HTTPPing(config *Config) {
if len(latencies) > 0 {
fmt.Printf("%s\n", stats.PingStatsFromLatencies(latencies).String())
}

os.Exit(0)
}
1 change: 1 addition & 0 deletions app/pinger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

// Answer is the out of a measurement done as an HTTP ping
type Answer struct {
Proto string
Duration time.Duration
StatusCode int
Bytes int64
Expand Down
46 changes: 16 additions & 30 deletions app/webclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ func (webClient *WebClient) resolve(host string) (*net.IPAddr, error) {

// WebClient represents an HTTP/S client designed to do performance analysis
type WebClient struct {
connCounter *ConnCounter
httpClient *http.Client
reused bool
connTarget string
config *Config
url *url.URL
dialCtx, dialTLSCtx func(ctx context.Context, network, addr string) (net.Conn, error)
connCounter *ConnCounter
httpClient *http.Client
reused bool
connTarget string
config *Config
url *url.URL
}

// NewWebClient builds a new instance of WebClient which will provides functions for Http-Ping
Expand All @@ -59,32 +58,15 @@ func NewWebClient(config *Config) (*WebClient, error) {
}

dialer := &net.Dialer{}
dialerTLS := &tls.Dialer{}

webClient.dialCtx = func(ctx context.Context, network, addr string) (net.Conn, error) {

dialCtx := func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := dialer.DialContext(ctx, network, webClient.connTarget)
if err != nil {
return conn, err
}
return webClient.connCounter.Bind(conn), nil
}

webClient.dialTLSCtx = func(ctx context.Context, network, addr string) (net.Conn, error) {
dialerTLS.Config = &tls.Config{
InsecureSkipVerify: webClient.config.NoCheckCertificate,
ServerName: webClient.url.Hostname(),
}

conn, err := dialerTLS.DialContext(ctx, network, webClient.connTarget)

if err != nil {
return conn, err
}

return webClient.connCounter.Bind(conn), nil
}

jar, _ := cookiejar.New(nil)

webClient.httpClient = &http.Client{
Expand All @@ -96,13 +78,16 @@ func NewWebClient(config *Config) (*WebClient, error) {
}

webClient.httpClient.Transport = &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: webClient.dialCtx,
DialTLSContext: webClient.dialTLSCtx,
Proxy: http.ProxyFromEnvironment,
DialContext: dialCtx,

TLSClientConfig: &tls.Config{
InsecureSkipVerify: config.NoCheckCertificate,
},

ForceAttemptHTTP2: true,
MaxIdleConns: 1,
DisableKeepAlives: webClient.config.DisableKeepAlive,
MaxIdleConns: 10,
DisableKeepAlives: config.DisableKeepAlive,
IdleConnTimeout: config.Interval + config.Wait,
}

Expand Down Expand Up @@ -183,6 +168,7 @@ func (webClient *WebClient) DoMeasure() *Answer {
}

return &Answer{
Proto: res.Proto,
Duration: d,
StatusCode: res.StatusCode,
Bytes: s,
Expand Down

0 comments on commit da8144b

Please sign in to comment.