normalizeBody example

if (!isset($options['normalized_headers']['content-type'])) {
                $options['normalized_headers']['content-type'] = ['Content-Type: application/json'];
            }
        }

        if (!isset($options['normalized_headers']['accept'])) {
            $options['normalized_headers']['accept'] = ['Accept: */*'];
        }

        if (isset($options['body'])) {
            $options['body'] = self::normalizeBody($options['body']$options['normalized_headers']);

            if (\is_string($options['body'])
                && (string) \strlen($options['body']) !== substr($h = $options['normalized_headers']['content-length'][0] ?? '', 16)
                && ('' !== $h || '' !== $options['body'])
            ) {
                if ('chunked' === substr($options['normalized_headers']['transfer-encoding'][0] ?? '', \strlen('Transfer-Encoding: '))) {
                    unset($options['normalized_headers']['transfer-encoding']);
                    $options['body'] = self::dechunk($options['body']);
                }

                $options['normalized_headers']['content-length'] = [substr_replace($h ?: 'Content-Length: ', \strlen($options['body']), 16)];
            }
 elseif ($body = $trace['options']['body'] ?? null) {
            if (\is_string($body)) {
                if (!$this->argMaxLengthIsSafe($body)) {
                    return null;
                }
                try {
                    $dataArg[] = '--data '.escapeshellarg($body);
                } catch (\ValueError) {
                    return null;
                }
            } elseif (\is_array($body)) {
                $body = explode('&', self::normalizeBody($body));
                foreach ($body as $value) {
                    if (!$this->argMaxLengthIsSafe($payload = urldecode($value))) {
                        return null;
                    }
                    $dataArg[] = '--data '.escapeshellarg($payload);
                }
            } else {
                return null;
            }
        }

        
$headers = [
            'content-type' => ['Content-Type: multipart/form-data; boundary=ABCDEF'],
        ];
        $body = [
            'foo[]' => 'bar',
            'bar' => [
                $file,
            ],
        ];

        $body = self::normalizeBody($body$headers);

        $result = '';
        while ('' !== $data = $body(self::$CHUNK_SIZE)) {
            $result .= $data;
        }

        $expected = <<<'EOF' --ABCDEF Content-Disposition: form-data; name="foo[]" bar --ABCDEF Content-Disposition: form-data; name="bar[0]"; filename="test.txt" Content-Type: text/plain foobarbaz --ABCDEF--
Home | Imprint | This part of the site doesn't use cookies.