Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(encoding): Fix double-encoding of HTTP response (#220) #221

Conversation

spinnakerbot
Copy link
Contributor

ecba3ea added a call to encode
the response body before sending it to the server if the body is
of type str.

This is the correct behavior for python 3, where str represents a
an unencoded string, but is incorrect for python 2. In python 2,
str represents an already-encoded string and unicode represents
an unencoded string.

This is breaking for prometheus monitoring, which is sending already-
encoded bytes to the respond() function. In python 2, those have type
str, so we're trying to re-encode them. This works fine as long as there
are only ASCII characters in the string, but breaks otherwise.

In order to support both python 2 and 3, try to use 'unicode' (as
exists in 2) and if it's absent assign str to unicode.

Automated cherry pick of 59cbbec into 1.16

ecba3ea added a call to encode
the response body before sending it to the server if the body is
of type str.

This is the correct behavior for python 3, where str represents a
an unencoded string, but is incorrect for python 2. In python 2,
str represents an already-encoded string and unicode represents
an unencoded string.

This is breaking for prometheus monitoring, which is sending already-
encoded bytes to the respond() function. In python 2, those have type
str, so we're trying to re-encode them. This works fine as long as there
are only ASCII characters in the string, but breaks otherwise.

In order to support both python 2 and 3, try to use 'unicode' (as
exists in 2) and if it's absent assign str to unicode.
@louisjimenez louisjimenez merged commit f626bb6 into release-1.16.x Oct 7, 2019
@louisjimenez louisjimenez deleted the auto-cherry-pick-1.16-59cbbec589f982864cee45d20c99c32d39c75f7f branch October 7, 2019 14:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants