SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Curl & Gzip

Hybrid View

  1. #1
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Curl & Gzip

    I'm writing a function to test if a remote file is being send as gzipped or not.
    I was hoping to figure this out using Curl and the response headers yet noting shows up.

    function return_headers($url){
    $curl = curl_init($url);
    $agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
    curl_setopt($curl,CURLOPT_COOKIEFILE,"cookie.txt");
    curl_setopt($curl,CURLOPT_COOKIEJAR,"cookie.txt");
    curl_setopt($curl,FOLLOWLOCATION,true);
    curl_setopt($curl,CURLOPT_USERAGENT,$agent);
    curl_setopt($curl,CURLOPT_HEADER, true);
    curl_setopt($curl,CURLOPT_NOBODY ,false);
    $headers = curl_exec($curl);
    //get the download size of page
    return $headers;
    }

    My function with Yahoo:
    HTTP/1.1 200 OK
    Date: Fri, 10 Apr 2009 11:25:59 GMT
    Set-Cookie: D=; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/; domain=.yahoo.com
    P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"
    Cache-Control: private
    Vary: User-Agent
    Set-Cookie: IU=deleted; expires=Thu, 10 Apr 2008 11:25:58 GMT; path=/; domain=.yahoo.com
    Set-Cookie: FPCM=deleted; expires=Thu, 10 Apr 2008 11:25:58 GMT; path=/
    Set-Cookie: PH=deleted; expires=Thu, 10 Apr 2008 11:25:58 GMT; path=/; domain=.yahoo.com
    Set-Cookie: D=_ylh=X3oDMTFka2FmZWo3BF9TAzI3MTYxNDkEcGlkAzEyMzkzNjE1ODgEdGVzdAMwBHRtcGwDaW5kZXgtbA--; path=/; domain=.yahoo.com
    Connection: close
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=utf-8

    Yet in firefox live headers I can see "Content-Encoding: gzip"

    Anyone know how this can be done plz?

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Send a HTTP header to Yahoo from cUrl that states you accept gzip encoding.

    If memory serves...

    PHP Code:
    curl_setopt($rCurlCURLOPT_HTTPHEADER, array('Accept-Encoding: gzip,deflate')); 
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Enthusiast toytron's Avatar
    Join Date
    Nov 2006
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    True indeed. Thnx

    function return_headers($url){
    $curl = curl_init($url);
    $agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5";
    curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept-Encoding: gzip,deflate'));
    curl_setopt($curl,CURLOPT_COOKIEFILE,"cookie.txt");
    curl_setopt($curl,CURLOPT_COOKIEJAR,"cookie.txt");
    curl_setopt($curl,FOLLOWLOCATION,true);
    curl_setopt($curl,CURLOPT_USERAGENT,$agent);
    curl_setopt($curl,CURLOPT_HEADER, true);
    curl_setopt($curl,CURLOPT_NOBODY ,true);
    $headers = curl_exec($curl);
    return $headers;
    }

    returns

    HTTP/1.1 200 OK Date: Fri, 10 Apr 2009 11:47:26 GMT Set-Cookie: D=; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/; domain=.yahoo.com P3P: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV" Cache-Control: private Vary: User-Agent Set-Cookie: IU=deleted; expires=Thu, 10 Apr 2008 11:47:25 GMT; path=/; domain=.yahoo.com Set-Cookie: FPCM=deleted; expires=Thu, 10 Apr 2008 11:47:25 GMT; path=/ Set-Cookie: PH=deleted; expires=Thu, 10 Apr 2008 11:47:25 GMT; path=/; domain=.yahoo.com Set-Cookie: D=_ylh=X3oDMTFkbTdlZWY4BF9TAzI3MTYxNDkEcGlkAzEyMzkzNjM2NjQEdGVzdAMwBHRtcGwDaW5kZXgtbA--; path=/; domain=.yahoo.com Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=utf-8 Content-Encoding: gzip 1


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •