scripting / Scripting-News

I'm starting to use GitHub for work on my blog. Why not? It's got good communication and collaboration tools. Why not hook it up to a blog?
121 stars 10 forks source link

In Node, piping a post results in garbage added #130

Closed scripting closed 5 years ago

scripting commented 5 years ago

I have a server running in Node that responds to HTTP POSTs.

It's being invoked through PagePark using its ability to delegate requests. Here's the actual code that does the delegation.

The message is transmitted to the proper server, it handles it properly, responds as it's supposed to, and PagePark transmits the response, with one problem. It adds extra characters before and after the response.

Here's a gist containing the actual response.

The characters added at the beginning of the response: 1f7

And at the end: 0

I have to admit I don't understand what the piping is doing, and I haven't found a way to debug this. So I'm looking for either possible answers, or possible ways to debug.

PeterJudgeZA commented 5 years ago

It's http chunking. Note the transfer-encoding header and lack of content-length. It's in the rfc https://tools.ietf.org/html/rfc7230#section-4.1

scripting commented 5 years ago

@PeterJudge-PSC -- thank you. That was exactly right.

I added a Content-Length header to the response from the server, and now it all works well.

Interesting to note -- It's an XML-RPC handler, and the XML-RPC spec clearly says the response must include a content-length header. Also it was a bug in my implementation of the client side that it didn't understand chunks. And my discomfort with pipes led me to believe the problem was probably there. It wasn't. ;-)

image