Force HTTP version

Default behaviour

Req works fine with HTTP/1.1, HTTP/2 and HTTP/3. If supported by the server, HTTP/2 is preferred by default, otherwise use HTTP/1.1, which is negotiated by the TLS handshake. If HTTP3 is enabled (EnableHTTP3), will use HTTP/3 if it is detected that the server supports HTTP3.

Force HTTP version

You can force using HTTP/1.1 if you want.

client := req.C().EnableForceHTTP1().EnableDumpAllWithoutBody()
GET /get HTTP/1.1
User-Agent: req/v3 (
Accept-Encoding: gzip

HTTP/1.1 200 OK
Date: Tue, 08 Feb 2022 02:30:18 GMT
Content-Type: application/json
Content-Length: 289
Connection: keep-alive
Server: gunicorn/19.9.0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true

And also you can force using HTTP/2 if you want, will return error if server does not support:

panic: Get "": server does not support http2, you can use http/1.1 which is supported

Similarly, you can also force using HTTP/3 if you want:


HTTP2 and H2C

If EnableForceHTTP2, h2c (HTTP2 over TCP) can be enabled when the http2 server does not use TLS:

client := req.C().DevMode().EnableForceHTTP2().EnableH2C()
2022/08/24 21:38:04.630003 DEBUG [req] HTTP/2 GET http://localhost:9000/
:authority: localhost:8972
:method: GET
:path: /
:scheme: http
accept-encoding: gzip
user-agent: req/v3 (

:status: 200
content-type: text/plain; charset=utf-8
content-length: 11
date: Wed, 24 Aug 2022 13:38:04 GMT

Hello World

Example code for h2c server:

package main

import (

func main() {
	handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprint(w, "Hello World")
	h2s := &http2.Server{}
	h1s := &http.Server{
		Addr:    ":9000",
		Handler: h2c.NewHandler(handler, h2s),