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 3 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
2 changes: 2 additions & 0 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func optionFlagSet() *pflag.FlagSet {
flags.String("http-debug", "", "log all HTTP requests and responses. Excludes body by default. To include body use '--http-debug=full'")
flags.Lookup("http-debug").NoOptDefVal = "headers"
flags.Bool("insecure-skip-tls-verify", false, "skip verification of TLS certificates")
flags.Bool("force-http1", false, "force requests to be sent over http1 protocol")
flags.Bool("no-connection-reuse", false, "disable keep-alive connections")
flags.Bool("no-vu-connection-reuse", false, "don't reuse connections between iterations")
flags.Duration("min-iteration-duration", 0, "minimum amount of time k6 will take executing a single iteration")
Expand Down Expand Up @@ -117,6 +118,7 @@ func getOptions(flags *pflag.FlagSet) (lib.Options, error) {
UserAgent: getNullString(flags, "user-agent"),
HTTPDebug: getNullString(flags, "http-debug"),
InsecureSkipTLSVerify: getNullBool(flags, "insecure-skip-tls-verify"),
ForceHTTP1: getNullBool(flags, "force-http1"),
NoConnectionReuse: getNullBool(flags, "no-connection-reuse"),
NoVUConnectionReuse: getNullBool(flags, "no-vu-connection-reuse"),
MinIterationDuration: getNullDuration(flags, "min-iteration-duration"),
Expand Down
12 changes: 12 additions & 0 deletions js/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,18 @@ func TestNewBundle(t *testing.T) {
assert.Equal(t, null.BoolFrom(true), b.Options.InsecureSkipTLSVerify)
}
})
t.Run("ForceHTTP1", func(t *testing.T) {
t.Parallel()
b, err := getSimpleBundle(t, "/script.js", `
export let options = {
forceHttp1: true,
};
export default function() {};
`)
if assert.NoError(t, err) {
assert.Equal(t, null.BoolFrom(true), b.Options.ForceHTTP1)
}
})
t.Run("TLSCipherSuites", func(t *testing.T) {
t.Parallel()
for suiteName, suiteID := range lib.SupportedTLSCipherSuites {
Expand Down
7 changes: 6 additions & 1 deletion js/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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 r.Bundle.Options.ForceHTTP1.Bool {
transport.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{} //send req over h1 protocol
} else {
_ = http2.ConfigureTransport(transport) //send over h2 protocol
}

cookieJar, err := cookiejar.New(nil)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions lib/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ type Options struct {
// Accept invalid or untrusted TLS certificates.
InsecureSkipTLSVerify null.Bool `json:"insecureSkipTLSVerify" envconfig:"K6_INSECURE_SKIP_TLS_VERIFY"`

// Force requests to be send over HTTP/1.1
ForceHTTP1 null.Bool `json:"forceHttp1" envconfig:"K6_FORCE_HTTP1"`

// Specify TLS versions and cipher suites, and present client certificates.
TLSCipherSuites *TLSCipherSuites `json:"tlsCipherSuites" envconfig:"K6_TLS_CIPHER_SUITES"`
TLSVersion *TLSVersions `json:"tlsVersion" ignored:"true"`
Expand Down Expand Up @@ -480,6 +483,9 @@ func (o Options) Apply(opts Options) Options {
if opts.InsecureSkipTLSVerify.Valid {
o.InsecureSkipTLSVerify = opts.InsecureSkipTLSVerify
}
if opts.ForceHTTP1.Valid {
o.ForceHTTP1 = opts.ForceHTTP1
}
if opts.TLSCipherSuites != nil {
o.TLSCipherSuites = opts.TLSCipherSuites
}
Expand Down
10 changes: 10 additions & 0 deletions lib/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func TestOptions(t *testing.T) {
assert.True(t, opts.InsecureSkipTLSVerify.Valid)
assert.True(t, opts.InsecureSkipTLSVerify.Bool)
})
t.Run("ForceHTTP1", func(t *testing.T) {
opts := Options{}.Apply(Options{ForceHTTP1: null.BoolFrom(true)})
assert.True(t, opts.ForceHTTP1.Valid)
assert.True(t, opts.ForceHTTP1.Bool)
})
t.Run("TLSCipherSuites", func(t *testing.T) {
for suiteName, suiteID := range SupportedTLSCipherSuites {
t.Run(suiteName, func(t *testing.T) {
Expand Down Expand Up @@ -490,6 +495,11 @@ func TestOptionsEnv(t *testing.T) {
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
{"ForceHTTP1", "K6_FORCE_HTTP1"}: {
"": null.Bool{},
"true": null.BoolFrom(true),
"false": null.BoolFrom(false),
},
// TLSCipherSuites
// TLSVersion
// TLSAuth
Expand Down