im developing an http proxy in C#. my problem is reproducable outside of this language so if you can tell me of a better forum then that would be good, as i am stumped.
to cut a long story short:
sometimes, the response i get back from the server is g-zipped - that is, one header is "Content-Encoding: gzip". but the actual bytes that i get back are not correct. as an example, take the following. this can be reproduced using telnet, so its not my code thats wrong.
here is the header :
GET /www.new/app_full_proxy.php?app=2462715666&v=1&size=p&cksum=df4b829ed8cd6f0b6ee9cdea66632753&src=http%3A%2F%2Fsol.ltserv.net%2Ffbsms%2Ftheme%2Fdefault%2F HTTP/1.1
Accept: */*
Referer: http://www.facebook.com/home.php
Accept-Language: en-gb
UA-CPU: x86
Accept-Encoding: gzip
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.21022; .NET CLR 3.5.30729; .NET CLR 3.0.30618)
Proxy-Connection: Keep-Alive
Host: platform.ak.facebook.com
Cookie: [cookie details go here !]
and here is the response:
HTTP/1.1 200 OK
Server: Apache/1.3.41.fb2
X-Cnection: close
Content-Type: text/html; charset=utf-8
Content-Encoding: gzip
Content-Length: 20
Vary: Accept-Encoding
Date: Tue, 19 May 2009 10:34:43 GMT
Connection: keep-alive
? [the 20 bytes listed above]
as you can see this is just my facebook home-page requesting something. i've taken out the cookie details. the response i get back says the content length is 20 bytes long, and here they are:
0x1f
0x8b
0x08
0x00
0x00
0x00
0x00
0x00
0x00
0x03
0x03
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
0x00
bytes 0, 1 and 2 are correct - 0x1f and 0x8b are the 'magic numbers' for GZip, so this is definitely 'supposed to be' GZip data. then the 0x08 byte is to say use the 'deflate' compression, which is also correct. then the remaining bytes are just wrong - all null bytes with a couple of 3's thrown in.
if you create a sample C# Gzip application, and try to unzip the above bytes, you won't get an error, or an execption, you will just see the GZipStream.Read function return 0 bytes forever - and here lies my problem.
all i am doing is unzipping the data that the server is sending back. so why is the server sending back this response if it blatently cant be unzipped ?