-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
Milestone
Description
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_STREAMandEND_HEADERSflag 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_HEADERSflag. Subsequently, an empty data frame with anEND_STREAMflag 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.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
mchtech
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Hold