drupal_http_request() overrides the Host header from the parsed URL host: $options['headers']['Host'] = $uri['host']

However, if the Host header is explicitly set by the caller, drupal_http_request() should honor it.

Members fund testing for the Drupal project. Drupal Association Learn more

Comments

mfb created an issue. See original summary.

mvc’s picture

Trivial patch attached.

Note that with this patch, when setting the Host header explicitly, the caller will be responsible for also appending non-default port numbers as per the HTTP/1.1 spec.

rhclayto’s picture

Status: Needs review » Reviewed & tested by the community

RTBC. As mentioned, the patch is trivial, won't break anything (it's just some if checks), & it does what it says.

David_Rothstein’s picture

Issue tags: +Drupal 7.60 target
Dinesh18’s picture

Verified the patch manually and looks good to me.
+1 to RTBC

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Drupal 7.60 target +7.60 release notes

It seems like it would be of limited usefulness given that you already specify the URL... but if people want it, hey, why not allow it :)

Committed to 7.x - thanks!

  • David_Rothstein committed b09c86e on 7.x
    Issue #2555649 by mvc, mfb, rhclayto, Dinesh18: drupal_http_request()...
mvc’s picture

Thanks! Sometimes the Host header and the domain name in the URI are in fact different (such as testing a new vhost). You could do this in D8 with Guzzle like this: https://github.com/guzzle/guzzle/issues/1678

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.