go net/http: ErrContentLength not returned for too-long HTTP/2 body writes

pod7payv  于 5个月前  发布在  Go
关注(0)|答案(4)|浏览(71)
// ErrContentLength is returned by ResponseWriter.Write calls
// when a Handler set a Content-Length response header with a
// declared size and then attempted to write more bytes than
// declared.
ErrContentLength = errors.New("http: wrote more than the declared Content-Length")

Writing too many bytes to an HTTP/2 body doesn't return ErrContentLength , however, for two reasons:

  1. The HTTP/2 ResponseWriter returns a different error when detecting a too-long body.
  2. The accounting for how many bytes have been written can fail to detect a too-long body until after the ResponseWriter.Write call has returned.
    The existing test TestIdentityResponse fails when run in HTTP/2 mode.
2skhul33

2skhul331#

你好,@neild,我可以试一下吗?☺️

evrscar2

evrscar22#

嘿,@neild,我可以试一下吗?☺️
请试试!我很乐意审阅一个CL。

ulydmbyx

ulydmbyx3#

https://go.dev/cl/450255提到了这个问题:net/http: ResponseWriter checks for the Content-Length before writing it

zed5wv10

zed5wv104#

https://go.dev/cl/577415提到了这个问题:net/http: update HandlerWritesTooMuch test to allow different h1/h2 behavior

相关问题