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.prototype.serialize(plain) - single replace of NL with %0A breaks Content-Length #63
Comments
The content-length being calculated too early is certainly a bug. As for the replace, at first I thought the issue was just that it didn't replace them all (i.e. it should be: So the fixes would likely be to calculate content-lengths properly for each of the types as well as not doing that replace on the body. |
I agree that the plain-mode replace should be removed. The json-mode calculation looks fine because the stringify wraps the whole event, not just the body. As for the xml-mode calculation, there may be a need for htmlentity encoding before taking the length, however, I'm not clear on the intended use case. It may be that |
The content length is necessary since it tells you how many bytes of the stream to read for the body. Without that you wouldn't know how many bytes to parse for the message, and would have to do contextual parsing (which this lib and fsw don't do). Since Content-Length is the byte-length of the body to be read form the stream, it should be calculated after the body is completely encoded. There is a difference between the body and the message as well. A plain message sent over the stream actually looks like this:
First is the headers for the message followed by the event as the body of that message. Within the event are the headers followed by the body of that event. JSON would look like this:
Even though the content-length in the event for json/xml is superfluous, there is a chance fsw might be using it even in those scenarios because it does send it. For consistency sake if nothing else, I'd rather keep it in. |
Just published v1.1.9 of |
Just reviewed your 1.1.9 changes: In xml-mode you have omitted to test whether a body is present to encode. Also, in plain-mode, you have left the comment that talks of urlencoding NLs |
Xml does check if the body exist, just under the comment that says "add body". The I should remove that comment at some point, but is the change working for you? |
I can confirm that the change is working for me. Many thanks. |
The
Content-Length
header is calculated before the first\n
only is replaced with%0A
.Apart from the
content-length
then being wrong, is thisreplace
strictly necessary?In my case, this body:
<ATM>\n\t<version>1.5</version>\n\t<data>00000</data>\n</ATM>
becomes:
<ATM>%0A\t<version>1.5</version>\n\t<data>00000</data>\n</ATM>
which is nonsense to the recipient.
The text was updated successfully, but these errors were encountered: