douxun2023 2019-09-08 13:05
浏览 110

无法在http / 2传输中设置参数

I want to have a Go HTTP/2 client for contacting a HTTP/2 supported server using h2c. For which I used Go's http2 transport, but it does not provide options like connection timeout, disable keep-alive, idle connection timeout, etc. as provided by http transport.

I tried using ConfigureTransport function in http2 package but this doesn't work with h2c.

Code snippet which I used is:

protos := []string{"h2", "http/1.1"}
transport1 := &http.Transport{
    DisableCompression: !enableCompression,
    DisableKeepAlives:  !enableKeepAlive,
    DialContext: (&net.Dialer{
        Timeout: dialTimeout,
    }).DialContext,
    IdleConnTimeout:     idleConnectionTimeout,
    MaxIdleConnsPerHost: idleConnectionsPerHost,
    TLSClientConfig: &tls.Config{
        NextProtos: protos,
    },
}

if err := http2.ConfigureTransport(transport1); err != nil {
    fmt.Println(err.Error())
}

client := http.Client{
    Transport: transport1,
}

resp, err := client.Get("http://<server>/hello.html")

I was expecting communication over h2c to work with all the parameters specified. Am I missing something?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机
    • ¥20 程序进入HardFault_Handler
    • ¥15 oracle集群安装出bug
    • ¥15 关于#python#的问题:自动化测试