In the HttpClientCurlDelegate class when executing a CURL request POST data is always added with curl_setopt($ch, CURLOPT_POSTFIELDS, $request->data);.

While a request without CURLOPT_POSTFIELDS would look like

> GET /api/ HTTP/1.1
User-Agent: Drupal (+http://drupal.org/)
Host: 192.168.0.8
Accept: application/xml

CURL automatically adds a Content-Length: 0 and a Content-Type: application/x-www-form-urlencoded header:

> GET /api/ HTTP/1.1
User-Agent: Drupal (+http://drupal.org/)
Host: 192.168.0.8
Accept: application/xml
Content-Length: 0
Content-Type: application/x-www-form-urlencoded
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sanduhrs’s picture

Assigned: Unassigned » sanduhrs
Status: Active » Needs review
FileSize
695 bytes

Adding post data only if not empty fixes the problem for me.
Patch attached, please review.

sanduhrs’s picture

Well to more more accurate, we could also check f it's not NULL.
Patch attached.

sanduhrs’s picture

I'm trying to communicate with a BigBlueButton server which fails for GET requests because of the added POST data.
This behavior seems to be common.
It is even documented in drupal_http_request():

// Only add Content-Length if we actually have any content or if it is a POST
// or PUT request. Some non-standard servers get confused by Content-Length in
// at least HEAD/GET requests, and Squid always requires Content-Length in
// POST/PUT requests.

Added the above comment to the patch and adjusted the if statement accordingly.
Please review.

Hugo Wetterberg’s picture

Status: Needs review » Fixed

Fixed in 7.x-2.4

Hugo Wetterberg’s picture

Status: Fixed » Closed (fixed)