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

2

7

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

Blab answered 6/8, 2009 at 22:25 Comment(0)
H
17

"\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.

Haggai answered 6/8, 2009 at 22:30 Comment(1)
Old topic but here is my answer where I give a RequestHeader+ChunkedBody+AfterHeader example. It should illustrate how newlines work. https://mcmap.net/q/455665/-how-to-get-the-size-of-chunk-in-http-response-using-java-if-transfer-encoding-is-chunkedNomination
Z
5

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.

Zebe answered 6/8, 2009 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.