0
votes

I) My proxy server passes the Accept-Encoding header that it received from the client to my back-end content server as-it-is. Data received from backend server is sent to the requesting browser simply using PHP echo (without processing headers separately). However, the data gets displayed in the browser as raw binary data.

If I do not pass any Accept-Encoding to my content server, then everything is fine.

Since the browser accepts GZIP data, why does my proxy server need to decode it - why doesn't directly passing the gzip data back to the browser work? Rather than gunzipping the data on proxy server, is there some setting I am missing that will make things work?


II) Based on stillstanding's suggestions, I tried a new way (but now I am more confused as it has its own problems)!.

I used

....
curl_setopt($curl_handle, CURLOPT_HEADER, 1);
$result = curl_exec($curl_handle);
curl_close($curl_handle);

and instead of echoing the result, I do:

list($headers,$content)=explode("\r\n\r\n",$result,2);
foreach (explode("\r\n",$headers) as $hdr) {
     header($hdr);
}
echo $content;

Now, the browser recognizes that the data is gzipped, but gives option to save the gzip file instead of displaying the contents. As mentioned earlier, I am just passing the Accept-Encoding that browser gives me, then why the issue?

thanks

JP

PS: (I have seen some other questions on SO related to curl gzip, but they are unable to resolve my doubt).

1
Does the browser receive the "Content-Encoding" header?bcosca
Didn't check. Now that you mention, most probably not. How can I check? Also: Shouldn't my backend-server send the Content-Encoding header? Or is it that my proxy server is eating it up? AFAIK, my backend server sees as if the request is from the browser, not the proxy.JP19
To check headers in Chrome: Developer Tools (CTRL+ALT+I), choose "Resources" (enable panel if you have to) from the top tabs, then "Documents" (exactly below "Resources"), then what is probably the only item in the left-hand list of documents, then finally "Headers" in the right pane.Jon
Thanks. Was parallely looking this up and am able to view headers in chrome.JP19

1 Answers

0
votes

The comments, some more google search and trial and error helped me fix the problem.

My curl was set (without me doing anything) to automatically deflate the response sent by the backend server. So the headers received by the browser said "gzip", but data received was not.

Stopped curl from deflating the response by:

curl_setopt($curl_handle, CURLOPT_ENCODING, "identity");

and now I can just echo the result as it is and works fine.