Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/Force HTTP1 functionality #2222

Merged
merged 21 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"net"
"net/http"
"net/http/cookiejar"
"os"
"runtime/debug"
"strconv"
"strings"
Expand Down Expand Up @@ -210,7 +211,12 @@ func (r *Runner) newVU(idLocal, idGlobal uint64, samplesOut chan<- stats.SampleC
MaxIdleConns: int(r.Bundle.Options.Batch.Int64),
MaxIdleConnsPerHost: int(r.Bundle.Options.BatchPerHost.Int64),
}
_ = http2.ConfigureTransport(transport)

if ForceHTTP1() {
transport.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{} //send over h1 protocol
} else {
_ = http2.ConfigureTransport(transport) //send over h2 protocol
}

cookieJar, err := cookiejar.New(nil)
if err != nil {
Expand Down Expand Up @@ -262,6 +268,23 @@ func (r *Runner) newVU(idLocal, idGlobal uint64, samplesOut chan<- stats.SampleC
return vu, nil
}

// Will check if force http1 env variable has been set in order to force requests to be sent over h1
// This feature is temporary until #936 is resolved
func ForceHTTP1() bool {
godebug := os.Getenv("GODEBUG")
if godebug == "" {
return false
}
variables := strings.SplitAfter(godebug, ",")

for _, v := range variables {
if strings.Trim(v, ",") == "http2client=0" {
return true
}
}
return false
}

// Setup runs the setup function if there is one and sets the setupData to the returned value
func (r *Runner) Setup(ctx context.Context, out chan<- stats.SampleContainer) error {
setupCtx, setupCancel := context.WithTimeout(ctx, r.getTimeoutFor(consts.SetupFn))
Expand Down
2 changes: 1 addition & 1 deletion lib/netext/httpext/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"net/url"
"testing"

"github.com/sirupsen/logrus"
"go.k6.io/k6/lib"
"go.k6.io/k6/stats"
"github.com/sirupsen/logrus"
)

func BenchmarkMeasureAndEmitMetrics(b *testing.B) {
Expand Down