protected function prepareDefaults($options): array
    {
        $defaults = $this->configs;

        if (! empty($defaults['headers'])) {
            // Default headers are only added if they are not present.
            $defaults['_headers'] = $defaults['headers'];
            unset($defaults['headers']);
        }

        // Special handling for headers is required as they are added as
        if (array_key_exists('headers', $options)) {
            // Allows default headers to be unset.
            if ($options['headers'] === null) {
                $defaults['_headers'] = null;
                unset($options['headers']);
            } elseif (! \is_array($options['headers'])) {
                throw new \InvalidArgumentException('headers must be an array');
            }
        }

        // Shallow merge defaults underneath options.
        $result = array_replace($defaults, $options);

        // Remove null values.
        foreach ($result as $k => $v) {
            if ($v === null) {
                unset($result[$k]);
            }
        }

        return $result;
    }