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

Event bridges cannot tell if structured JSON data is base64 encoded. #371

Closed
alanconway opened this issue Jan 18, 2019 · 9 comments
Closed

Comments

@alanconway
Copy link
Contributor

I am implementing a bridge between different event transport bindings and formats:
https://godoc.org/github.com/alanconway/scratch/lightning
I don't know how to correctly determine if a JSON structured data attribute is base64 encoded or not.

Spec says: "If the contenttype media type is known to contain text, the data attribute value is not further interpreted and treated as a text string. Otherwise, it is decoded and treated as a binary value."

I'm not aware of a reliable way to determine that a MIME type is "known to contain text". RFC1341 provides an explicit Content-Transfer-Encoding when data is encoded, it does not expect mail clients to "just know". My nasty hack is to use this regexp to detect "non-text" media-types, clearly not reliable or future-proof:
/(^$)|(^text$)|(^text/)|(^application.*/+-./+-.)/

I think the JSON format should have a "contenttransferencoding" attribute (rfc1341 compliant) - as should future formats that can't handle raw binary data. It doesn't have to be part of the abstract event, but it would reduce re-encoding if it was: base64 encoded data could flow unmodified through different binary and structured event bindings and only be decoded when the body is actually required.

This is related to #261 but I think deserves separate treatment since it affects the core use case of events - accurately forwarding event data - even if you don't care about corner cases like binary values in Maps.

@duglin
Copy link
Collaborator

duglin commented Jan 24, 2019

I'm kind of surprised that there's no way to encode this information into the Content-Type header.
@clemensv any thoughts on this?

@alanconway
Copy link
Contributor Author

alanconway commented Jan 24, 2019 via email

@clemensv
Copy link
Contributor

As much as it pains me - @alanconway is right.

Since this is a specific JSON structured format problem, I wonder whether we can add an attribute that only applies to the structured JSON encoding, preferably inside the event format spec, and that attribute MUST be set when the transfer encoding is anything but plain text or an embedded JSON graph.

@alanconway
Copy link
Contributor Author

alanconway commented Jan 29, 2019 via email

@duglin
Copy link
Collaborator

duglin commented Feb 7, 2019

@clemensv were you going to PR this one?

@duglin
Copy link
Collaborator

duglin commented Feb 12, 2019

@clemensv any chance of getting a PR for this one in time for this week's call?

@n3wscott
Copy link
Member

I just bumped into this one too. I want to base64 encode my payload but I can not.

@n3wscott
Copy link
Member

This is fixed now!

@duglin
Copy link
Collaborator

duglin commented Jun 8, 2019

I believe we can close this now that #387 is merged. @alanconway please speak up if I'm wrong and we need to reopen it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants