drdzpknk76046 2019-09-12 08:56
浏览 102
已采纳

转到http客户端不会自动将主体脱壳

I'm streaming http from Go and the server responds with "Transfer-Encoding: chunked" as expected. And I've been told that the http client in Go shall automatically dechunk the body from the http response, removing the . But in my case it isn't removed automatically, so I have to use a ChunkedReader to read the bodies.

Any idea why golang doesn't dechunk my body automatically?

EDIT: Here is the http request:

var transport = http.Transport{
  Proxy:                  nil,
  ExpectContinueTimeout:  0,
  MaxResponseHeaderBytes: 16384}

var httpClient = http.Client{
  Transport: &transport,
  CheckRedirect: func(req *http.Request, via []*http.Request) error {
    return http.ErrUseLastResponse
}}

bodyReader, bodyWriter := io.Pipe()
req, _ := http.NewRequest("GET", "http://x.x.x.x/stream", bodyReader)
response, err := httpClient.Do(req)

buffer := make([]byte, 2 << 15)
n, readErr = response.Body.Read(buffer)   <-- should be dechunked body

The data read into the buffer is not dechunked. Any idea why?

  • 写回答

1条回答

  • dongyoucha0645 2019-09-18 11:27
    关注

    I figured out why the body is not dechunked automatically. It's because the HTTP response was HTTP/1.0. In which case golang ignores the transfer encoding header.

    https://github.com/golang/go/issues/12785

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 微信小游戏反编译后,出现找不到分包的情况
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)