How do I troubleshoot responses with WP HTTP API?

I make a GET call to API, call is supposed to return no data:

  • browser (and sniffer) give me 200-OK response with null text as body;
  • wp_remote_get() gives me 200-OK response with string of binary garbage as body.

Other API requests (that are supposed to and do return non-empty data) work perfectly fine.

Where to start poking HTTP API to figure out why it ends up with garbage?

Here is dump of full response data:

array
  'headers' => 
    array
      'date' => string 'Tue, 22 Feb 2011 16:51:03 GMT' (length=29)
      'server' => string 'Apache/2.2.3 (Red Hat)' (length=22)
      'x-powered-by' => string 'PHP/5.2.16' (length=10)
      'content-encoding' => string 'deflate' (length=7)
      'vary' => string 'Accept-Encoding' (length=15)
      'content-length' => string '17' (length=2)
      'connection' => string 'close' (length=5)
      'content-type' => string 'application/json; charset=utf-8' (length=31)
  'body' => string 'x��+��������_' (length=17)
  'response' => 
    array
      'code' => int 200
      'message' => string 'OK' (length=2)
  'cookies' => 
    array
      empty

2 Answers
2

We tracked it down to content-encoding’ => string ‘deflate’ (length=7) being at fault.

WP_HTTP is adding in a deflate header for no reason and un gzip compressing the results.
It only happens when the body of the response is under a certain string length.

Very annoying when all you want isa 1 or a 0.

A query to WP_Hackers hasn’t resulted in a fix.
Might have to chase it up further…..

Leave a Comment