hgweb: refactor the request draining code

Authored by indygreg on Mar 9 2018, 8:23 PM.



The previous code for draining was only invoked in a few places in
the wire protocol. Behavior wasn't consist. Furthermore, it was
difficult to reason about.

With us converting the input stream to a capped reader, it is now
safe to always drain the input stream when its size is known because
we can never overrun the input and read into the next HTTP request.
The only question is "should we?"

This commit changes the draining code so every request is examined.
Draining now kicks in for a few requests where it wouldn't before.
But I think the code is sufficiently restricted so the behavior is
safe. Possibly the most dangerous part of this code is the issuing
of Connection: close for POST and PUT requests that don't have a
Content-Length. I don't think there are any such uses in our WSGI
application, so this should be safe.

In the near future, I plan to significantly refactor the WSGI
response handling. I anticipate this code evolving a bit. So any
minor regressions around draining or connection closing behavior
might be fixed as a result of that work.

All tests pass with this change. That scares me a bit because it
means we are lacking low-level tests for the HTTP protocol.

Diff Detail

rHG Mercurial
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
indygreg created this revision.Mar 9 2018, 8:23 PM
indygreg updated this revision to Diff 6831.Mar 10 2018, 3:03 PM
durin42 accepted this revision.Mar 12 2018, 4:57 PM
This revision is now accepted and ready to land.Mar 12 2018, 4:57 PM
This revision was automatically updated to reflect the committed changes.