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

Merged
merged 1 commit into from
Oct 7, 2019
Merged

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

merged 1 commit into from
Oct 7, 2019

Conversation

ezimanyi
Copy link
Contributor

@ezimanyi ezimanyi commented Oct 4, 2019

Fixes spinnaker/spinnaker#4980

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.

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.
@ezimanyi
Copy link
Contributor Author

ezimanyi commented Oct 4, 2019

I was able to successfully get the /prometheus_metrics endpoint of the monitoring daemon to return an emoji with this change, whereas I got the same error as in the linked issue before this change.

Copy link
Contributor

@maggieneterval maggieneterval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔨 🐛 👬 🔣 💻 📜

@ezimanyi ezimanyi merged commit 59cbbec into spinnaker:master Oct 7, 2019
@ezimanyi ezimanyi deleted the fix-encoding branch October 7, 2019 14:07
@ezimanyi
Copy link
Contributor Author

ezimanyi commented Oct 7, 2019

@spinnakerbot 🍒 ⛏️ 1.16

@ezimanyi
Copy link
Contributor Author

ezimanyi commented Oct 7, 2019

@spinnakerbot 🍒 ⛏️ 1.16

spinnakerbot pushed a commit that referenced this pull request Oct 7, 2019
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.
@spinnakerbot
Copy link
Contributor

Cherry pick successful: #221

louisjimenez pushed a commit that referenced this pull request Oct 7, 2019
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants