views:

170

answers:

2

I have a simple proxy source in C++. I'm trying to modify it to inject some html content into specific pages. I'v managed to get it working but whenever I inject something, part of the original html gets corrupted. I know for a fact that it's not my string handling functions because I have it printing out the result before sending and it's fine. The html is transmitted 1460 bytes at a time and there is a 3 character string followed newline at the top of each chunk and then at the very end there is a newline and a 0;

Example:

fef
some html

co7
some html 

81f
final html
0

Iv been searching and trying to figure out what those three characters represent. Remaining content length hexed? maybe some sort of hash? but I can't find anything. But I'm guessing they're the source of the problem. Any help/insight is appreciated.

A: 

Is the server you are proxying specifying the size of the response in a header? If so, and you're modifying the response body without updating the header, you might get strange errors like this one.

Hank Gay
The response header does get updated before being sent to the client.
silverbandit91
+2  A: 

Chunked Encoding? See RFC 2616, Section 3.6.1.

Julian Reschke
I read it over and now I'm pretty sure this is the source of error. Thank you very much.
silverbandit91
This was going to be my guess.
jmucchiello
yes this fixed it. The characters are the length of the chunk in hex in case anyone is interested.
silverbandit91