Skip to content

Commit

Permalink
reducing the complexity, extracted http/3 redirection
Browse files Browse the repository at this point in the history
  • Loading branch information
rbarazzutti committed Aug 17, 2023
1 parent fb971c9 commit dfa2008
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion app/http3.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (c connAdapter) RemoteAddr() net.Addr {
return c.remoteAddr
}

func CheckAltSvcH3Header(h http.Header) *string {
func checkAltSvcH3Header(h http.Header) *string {
for k, entries := range h {
if strings.ToUpper(k) == "ALT-SVC" {
for _, entry := range entries {
Expand Down
55 changes: 29 additions & 26 deletions app/webclientimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,35 +343,15 @@ func (webClient *webClientImpl) DoMeasure(followRedirect bool) *HTTPMeasure {
}

altSvcH3 := ""
if res != nil {
if val := CheckAltSvcH3Header(res.Header); val != nil {
altSvcH3 = *val
}

if val := checkAltSvcH3Header(res.Header); val != nil {
altSvcH3 = *val
}

if altSvcH3 != "" && !strings.HasPrefix(res.Proto, "HTTP/3") && !webClient.config.Http1 && !webClient.config.Http2 {
_, _ = fmt.Printf(" ─→ server advertised HTTP/3 endpoint, using HTTP/3\n")

if altSvcH3 == ":443" {
// nothing
} else if strings.HasPrefix(altSvcH3, ":") {
webClient.url.Host = webClient.url.Host + altSvcH3
} else {
webClient.url.Host = altSvcH3
}

c := *webClient.config
c.Http3 = true
err := webClient.update(&c, webClient.runtimeConfig)

if err != nil {
return &HTTPMeasure{
IsFailure: true,
FailureCause: err.Error(),
MeasuresCollection: timerRegistry.Measure(),
}
}
return webClient.DoMeasure(followRedirect)
return webClient.moveToHttp3(altSvcH3, timerRegistry, followRedirect)
}

timerRegistry.Get(stats.ReqAndWait).Stop()
Expand Down Expand Up @@ -426,8 +406,7 @@ func (webClient *webClientImpl) DoMeasure(followRedirect bool) *HTTPMeasure {
}

return &HTTPMeasure{
Proto: res.Proto,
//TotalTime: timerRegistry.get(Total).measure(),
Proto: res.Proto,
StatusCode: res.StatusCode,
Bytes: s,
InBytes: i,
Expand All @@ -448,3 +427,27 @@ func (webClient *webClientImpl) DoMeasure(followRedirect bool) *HTTPMeasure {
}

}

func (webClient *webClientImpl) moveToHttp3(altSvcH3 string, timerRegistry *stats.TimerRegistry, followRedirect bool) *HTTPMeasure {

if altSvcH3 == ":443" {
// nothing
} else if strings.HasPrefix(altSvcH3, ":") {
webClient.url.Host = webClient.url.Host + altSvcH3
} else {
webClient.url.Host = altSvcH3
}

c := *webClient.config
c.Http3 = true
err := webClient.update(&c, webClient.runtimeConfig)

if err != nil {
return &HTTPMeasure{
IsFailure: true,
FailureCause: err.Error(),
MeasuresCollection: timerRegistry.Measure(),
}
}
return webClient.DoMeasure(followRedirect)
}

0 comments on commit dfa2008

Please sign in to comment.