Improve the code consistency and testing for HttpRequest.
Review Request #10463 — Created March 21, 2019 and submitted
HttpRequestis a pretty old class, and was created before we had a lot
of our current code and documentation standards in place. As it evolved
to be compatible with Python 2.x and 3.x, we ended up with some (mostly
harmless) inconsistency in its behavior on these versions that weren't
caught by the very minimal test suite we had in place
This change fleshes out
HttpRequest, adding docs, improving the
readability of some code, and bringing consistency in how it handles
string types. String types for form fields and files are now normalized
to byte strings when setting them, rather than accepting any string type
and leaving it up to the encoding stage to deal with them. This gives us
something stable we can work with.
Small discrepencies like the ordering of files and fields have been
resolved. They're now encoded in insert order, rather than Python
dictionary iteration order (which varies across 2.x and various 3.x
releases). Our old unit tests didn't catch this.
This also trims the fat, getting rid of field/file deletion methods,
which were never used anywhere and, in the case of file deletion, had
a misleading argument.
The unit test suite has been fleshed out some, doing a better job of
testing normalization and building of various fields and testing the
actual encoded payload instead of relying on a hand-crafted and
simplistic form-data parser.
Unit tests passed on Python 2.x and 3.x.
Used these changes to post this review request.