Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept-Encoding as Request Header #4

Open
nader14y opened this issue Aug 9, 2019 · 6 comments
Open

Accept-Encoding as Request Header #4

nader14y opened this issue Aug 9, 2019 · 6 comments

Comments

@nader14y
Copy link

nader14y commented Aug 9, 2019

Accept-Encoding as Request Header

This library is sending only Accept and Authentication params as Header of the Request::request(). Some API providers like MLSGrid need to send more params (like Accept-Encoding) as a Header.

@phoenixwade
Copy link

I'd be very interested in this, MLSGrid is only communicating on a compressed stream starting on Aug 14th.

@theodorebear
Copy link

same! working with MLS Grid which requires compressed gzip.

@theodorebear
Copy link

can anyone verify that #5 works?

@clauz
Copy link

clauz commented Aug 28, 2020

I forked this project for several reasons, this issue being one of them. I would be more than happy to push a PR.

@carterterryw
Copy link

can anyone verify that #5 works?

I can verify that the modifications do in fact work for MLSGrid requests. The only other modification I had to do was to gzdecode() the returned data since for some reason that piece was not automatic.

@jaybeaton
Copy link

jaybeaton commented May 16, 2024

The simplest solution is to update the curl options to set CURLOPT_ACCEPT_ENCODING. If this is set to an empty string, curl will automatically send the appropriate header based on the supported algorithms and automatically decode the response.

Sets the contents of the Accept-Encoding: header sent in an HTTP request, and enables decoding of a response when a Content-Encoding: header is received.

libcurl potentially supports several different compressed encodings depending on what support that has been built-in.

To aid applications not having to bother about what specific algorithms this particular libcurl build supports, libcurl allows a zero-length string to be set ("") to ask for an Accept-Encoding: header to be used that contains all built-in supported encodings.

This is the only change required for it to work correctly with MLSGrid (and any others, I'd guess), and it does not cause any problems with our other RESO providers:

diff --git a/lib/HttpClient/CurlClient.php b/lib/HttpClient/CurlClient.php
index f27f4c98f..53da6c1bf 100644
--- a/lib/HttpClient/CurlClient.php
+++ b/lib/HttpClient/CurlClient.php
@@ -173,6 +173,7 @@ public function request($method, $absUrl, $headers, $params, $hasFile)
         $opts[CURLOPT_CONNECTTIMEOUT] = $this->connectTimeout;
         $opts[CURLOPT_TIMEOUT] = $this->timeout;
         $opts[CURLOPT_HEADERFUNCTION] = $headerCallback;
+        $opts[CURLOPT_ACCEPT_ENCODING] = '';
         if($headers) {
             $opts[CURLOPT_HTTPHEADER] = $headers;
         }

From the curl docs:

This option was called CURLOPT_ENCODING before 7.21.6

The specific libcurl you are using must have been built with zlib to be able to decompress gzip and deflate responses, with the brotli library to decompress brotli responses and with the zstd library to decompress zstd responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants