Skip to content

Commit

Permalink
Add calc length options #1063
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Dec 10, 2024
1 parent 74d0c0c commit aa150fd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/dom/src/HTMLElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ class HTMLElement extends NativeHTMLElement implements \ArrayAccess
* @param mixed|null $content
*
* @return DOMElement
*
* @deprecated Use HTMLElement::new() instead.
*/
#[\Deprecated(message: 'Use HTMLDomFactory::element() instead.')]
public static function create(string $name, array $attributes = [], mixed $content = null): DOMElement
{
return DOMElement::create($name, $attributes, $content)->asHTML();
Expand Down
7 changes: 5 additions & 2 deletions packages/http/src/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function prepareRequestOptions(array $options): array
[
'ignore_curl_error' => false,
'allow_empty_status_code' => false,
'auto_calc_content_length' => true,
'write_stream' => 'php://memory',
'timeout' => null,
'user_agent' => null,
Expand Down Expand Up @@ -305,7 +306,9 @@ protected function prepareCurlOptions(RequestInterface $request, array $options)
$request = static::prepareHeaders($request, $forceMultipart);

// Add the relevant headers.
if (isset($opt[CURLOPT_POSTFIELDS]) && $opt[CURLOPT_POSTFIELDS] !== '') {
$calcLength = (bool) ($options['auto_calc_content_length'] ?? true);

if ($calcLength && isset($opt[CURLOPT_POSTFIELDS]) && $opt[CURLOPT_POSTFIELDS] !== '') {
$request = $request->withHeader('Content-Length', (string) strlen($opt[CURLOPT_POSTFIELDS]));
}

Expand Down Expand Up @@ -333,7 +336,7 @@ protected function prepareCurlOptions(RequestInterface $request, array $options)
$opt[CURLOPT_RETURNTRANSFER] = true;

// Override the Expect header to prevent cURL from confusing itself in its own stupidity.
// Link: http://the-stickman.com/web-development/php-and-curl-disabling-100-continue-header/
// @see https://stackoverflow.com/questions/14158675/how-can-i-stop-curl-from-using-100-continue
$opt[CURLOPT_HTTPHEADER][] = 'Expect:';

/*
Expand Down

0 comments on commit aa150fd

Please sign in to comment.