drupal_http_request() vs Accept-Encoding

Created on 18 April 2023, almost 2 years ago

Problem/Motivation

I’m using drupal_http_request() to make API calls. Some APIs encode their responses and thus my code has to deal with encoded values. This seems like something drupal_http_request() should deal with. It doesn’t send a Accept-Encoding header which means that tells servers it accepts any encoding:

If no Accept-Encoding header field is in the request, any content coding is considered acceptable by the user agent.

https://www.rfc-editor.org/rfc/rfc9110.html#section-12.5.3-10.1

Steps to reproduce

Make a HTTP request to a server that encodes its responses: See that the returned $response->data is encoded.

Proposed resolution

There are multiple options to handle this:

  • Specify Accept-Encoding: identity
  • Implement decoding for gzip/deflate and add the corresponding header Accept-Encoding: gzip, deflate

Remaining tasks

Decide whether this is still worth implementing in D7.

User interface changes

None

API changes

If decompression is implemented the Accept-Encoding should be removed from the $response so that code working around this bug doesn’t attempt to decode a second time.

Data model changes

None

Release notes snippet

tbd

🐛 Bug report
Status

Active

Version

7.0 ⚰️

Component
Base 

Last updated 41 minutes ago

Created by

🇦🇹Austria torotil

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024