Page 1 of 1

Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 9:34 am
by Peter Kelly
So I have had a look around on google and I can find sites to test the ENCODING of a website e.g if it has gzip or deflate enabled but how do you actually get these headers? Because this is included in the request and not the response :/

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 11:51 am
by twinedev
Check these out to see if they will work for ya:

http://us3.php.net/manual/en/function.headers-list.php
http://us3.php.net/manual/en/function.a ... eaders.php

If you are wanting to just see what your page gives when you browse it, the easiest way would be to use WebDeveloper Toolbar for Firefox (http://chrispederick.com/work/web-developer/), a must have for web developers, only second to Firebug. In the menu, Choose "View Response Headers" at the bottom of the Information menu.

Another great way (on a windows machine), is to run Fiddler, which by normal installs tracks all http requests and can show you all kinds of information, including header information. (This is another great tool for developers, helps a TON for tracing AJAX calls as you can directly see the raw info sent and received from the server, as well as let you see how long it takes all components to load on the site)

-Greg

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 1:52 pm
by Peter Kelly
twinedev wrote:Check these out to see if they will work for ya:

http://us3.php.net/manual/en/function.headers-list.php
http://us3.php.net/manual/en/function.a ... eaders.php

If you are wanting to just see what your page gives when you browse it, the easiest way would be to use WebDeveloper Toolbar for Firefox (http://chrispederick.com/work/web-developer/), a must have for web developers, only second to Firebug. In the menu, Choose "View Response Headers" at the bottom of the Information menu.

Another great way (on a windows machine), is to run Fiddler, which by normal installs tracks all http requests and can show you all kinds of information, including header information. (This is another great tool for developers, helps a TON for tracing AJAX calls as you can directly see the raw info sent and received from the server, as well as let you see how long it takes all components to load on the site)

-Greg
I have looked at them in principle they would be ideal but they cant check a remote website.

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 2:27 pm
by Jade
Couldn't you just check with get_headers()?

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 2:34 pm
by Peter Kelly
Get_Headers is the response not the request so doesn't include the ENCODING. Basically all I want is to be able to detect if the page has been compressed using gzip or deflate etc.

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 3:25 pm
by Jade
Gah sorry I'm out of PHP based ideas then. Perhaps you could use something like WireShark and then save the results to a database. Not the greatest solution but at least you'd get the header data.

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 5:06 pm
by superdezign
If this is a one-time test, use this: http://www.whatsmyip.org/http_compression/

In order to check if the server is capable of serving up a GZIPped response in PHP, request one. You can do this by setting cURL's CURLOPT_ENCODING option to 'gzip'. This is the equivalent of a browser telling the server that it is capable of handling GZIPped responses. Now, technically this doesn't mean that a capable server has to serve you GZIPped content, but Apache will by default AFAIK.

You can check DEFLATE the same way.

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Mon Jun 27, 2011 9:14 pm
by flying_circus
superdezign wrote:If this is a one-time test, use this: http://www.whatsmyip.org/http_compression/

In order to check if the server is capable of serving up a GZIPped response in PHP, request one. You can do this by setting cURL's CURLOPT_ENCODING option to 'gzip'. This is the equivalent of a browser telling the server that it is capable of handling GZIPped responses. Now, technically this doesn't mean that a capable server has to serve you GZIPped content, but Apache will by default AFAIK.

You can check DEFLATE the same way.
I was just about to post a code sample for this. I am not sure I understand the original question completely. When the client sends a request, it may include an "Accept-Encoding" header (format: "Accept-Encoding: gzip, deflate"). This tells the server what the client is capable of understanding. Then the server responds with a "Content-Encoding" header which tells how the page was delivered (ex: "gzip");

Code: Select all

<?php declare(encoding = 'UTF-8');  
  // create a new cURL resource
    $ch = curl_init();

  // set URL and other appropriate options
    curl_setopt($ch, CURLOPT_URL, "http://devbox/");
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

  // grab URL and pass it to the browser
    curl_exec($ch);
    
  // Check if any error occured - Output Response Headers
    if(!curl_errno($ch))
     print_r(curl_getinfo($ch));
    
  // close cURL resource, and free up system resources
    curl_close($ch);

  /* Output
    HTTP/1.1 200 OK
    Date: Tue, 28 Jun 2011 02:12:35 GMT
    Server: Apache/2.2.17 (Ubuntu)
    X-Powered-By: PHP/5.2.17-0ubuntu0ppa2~maverick
    X-FRAME-OPTIONS: DENY
    Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
    Expires: Thu, 19 Nov 1981 08:52:00 GMT
    Pragma: no-cache
    Vary: Accept-Encoding
    Content-Encoding: gzip
    Content-Length: 2846
    Content-Type: text/html
  */
?>

Re: Remote Request Headers (GZIP/DEFLATE)

Posted: Tue Jun 28, 2011 1:42 am
by Peter Kelly
Oh rite I thought the server passed over the content-encoding even if you didnt send the client encoding. Thats cleared that up, thanks.