Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Chunked transfer encoding: How do you send "\r\n"?

Say the body I'm trying to send via chunked encoding includes "\r\n", how do I avoid that being interpreted as the chunk delimeter?

e.g. "All your base are\r\n belong to us"

http://en.wikipedia.org/wiki/Chunked_transfer_encoding

like image 803
Alex Black Avatar asked Aug 06 '09 22:08

Alex Black


2 Answers

"\r\n" isn't really a chunk delimiter. The chunk size specifies the number of bytes made up by that chunk's data. The client should then read the "\r\n" embedded within your message just fine.

like image 81
David Avatar answered Nov 05 '22 14:11

David


By design, that is not a problem at all. Each chunk specifies the byte size of its data block. The contents of each data block are arbitrary, and must be received as such, so it can include line breaks in it. If the client is reading each chunk correctly (read a line and parse the byte size from it, then read the specified number of bytes, then read a line break), it won't matter if there are line breaks in the data, since the client is reading the data based on byte size, not on line breaks.

like image 40
Remy Lebeau Avatar answered Nov 05 '22 16:11

Remy Lebeau