Skip to content

CURLRequest: HTTPHEADER and POSTFIELDS #445

Description

@matahr

This function never set HTTPHEADER option

Line: 402

        /**
	 * Takes all headers current part of this request and adds them
	 * to the cURL request.
	 *
	 * @param array $curl_options
	 */
	protected function applyRequestHeaders(array $curl_options = []): array
	{
		$headers = $this->getHeaders();
-		if (empty($head))
+		if (empty($headers))
		{
			return $curl_options;
		}
		$set = [];
		foreach ($headers as $name => $value)
		{
			$set[] = $name.': '.$this->getHeaderLine($name);
		}
		$curl_options[CURLOPT_HTTPHEADER] = $set;
		return $curl_options;
	}

cURL don't calculate Content-Length when HTTPHEADER is set and it is missing when the request is sent (php 7.0.15 ubuntu/yakkety), i don't know a workaround, so i forced it

Line: 655

		// Post Data - application/x-www-form-urlencoded
		if (! empty($config['form_params']) && is_array($config['form_params']))
		{
-			$curl_options[CURLOPT_POSTFIELDS] = http_build_query($config['form_params']);
+			$postfields = http_build_query($config['form_params']);
+			$curl_options[CURLOPT_POSTFIELDS] = $postfields;

-			if (empty($this->header('Content-Type')))
-			{
-				$this->setHeader('Content-Type', 'application/x-www-form-urlencoded');
-			}

+                      # This headers must be set
+			$this->setHeader('Content-Type', 'application/x-www-form-urlencoded');
+			$this->setHeader('Content-Length', (string) strlen($postfields));

		}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions