Issue
A server cannot differentiate between the below two scenarios:
- No body was sent - The final header frame of the h2 request contains the
END_STREAM and END_HEADERS flag and no data frame was sent after that
- An empty body was sent - The final header frame of the h2 request only contains the
END_HEADERS flag. Subsequently, an empty data frame with an END_STREAM flag is sent.
When reading the body on http.Request, both immediately return io.EOF and 0 bytes are read.
Proposal
Create http2.NoBody and http2.EmptyBody to represent the two scenarios and set the req.Body to them. http2.NoBody can equal http.NoBody as well.
Use Case
Some servers differentiate between the two kinds of requests. We're running a MITM proxy that needs to read which kind of request a client is making and forward the same to the target server.
Alternatives Considered
Add a method to http.Request (named ReadDataFrame?) that returns whether or not a client sent a data frame.
Personally, I prefer adding http2.NoBody and http2.EmptyBody.
Additional Notes
- When
req.Body is set to nil or http.NoBody, no data frame is sent by http2.Transport. If it's set to another reader that returns 0 bytes (ex: ioutil.NopCloser(strings.NewReader(""))), then an empty data frame is sent. This gives a way to differentiate between the two scenarios when sending requests but not when accepting requests through http.Server or http2.Server
Issue
A server cannot differentiate between the below two scenarios:
END_STREAMandEND_HEADERSflag and no data frame was sent after thatEND_HEADERSflag. Subsequently, an empty data frame with anEND_STREAMflag is sent.When reading the body on
http.Request, both immediately returnio.EOFand 0 bytes are read.Proposal
Create
http2.NoBodyandhttp2.EmptyBodyto represent the two scenarios and set thereq.Bodyto them.http2.NoBodycan equalhttp.NoBodyas well.Use Case
Some servers differentiate between the two kinds of requests. We're running a MITM proxy that needs to read which kind of request a client is making and forward the same to the target server.
Alternatives Considered
Add a method to
http.Request(namedReadDataFrame?) that returns whether or not a client sent a data frame.Personally, I prefer adding
http2.NoBodyandhttp2.EmptyBody.Additional Notes
req.Bodyis set tonilorhttp.NoBody, no data frame is sent byhttp2.Transport. If it's set to another reader that returns 0 bytes (ex:ioutil.NopCloser(strings.NewReader(""))), then an empty data frame is sent. This gives a way to differentiate between the two scenarios when sending requests but not when accepting requests throughhttp.Serverorhttp2.Server