Skip to content

Implement getHeaders method in Curl class#113

Open
mean-cj wants to merge 8 commits into
php-mod:masterfrom
mean-cj:master
Open

Implement getHeaders method in Curl class#113
mean-cj wants to merge 8 commits into
php-mod:masterfrom
mean-cj:master

Conversation

@mean-cj
Copy link
Copy Markdown
Contributor

@mean-cj mean-cj commented Jun 3, 2026

Add method to retrieve custom headers in Curl class.

Add method to retrieve custom headers in Curl class.
@nadar
Copy link
Copy Markdown
Member

nadar commented Jun 3, 2026

@mean-cj what about using this method to retrieve response headers?

 /**
     * Get a specific response header key or all values from the response headers array.
     *
     * Usage example:
     *
     * ```php
     * $curl = (new Curl())->get('http://example.com');
     *
     * echo $curl->getResponseHeaders('Content-Type');
     * ```
     *
     * Or in order to dump all keys with the given values use:
     *
     * ```php
     * $curl = (new Curl())->get('http://example.com');
     *
     * var_dump($curl->getResponseHeaders());
     * ```
     *
     * @param string $headerKey Optional key to get from the array.
     * @return bool|string|array
     * @since 1.9
     */

@mean-cj
Copy link
Copy Markdown
Contributor Author

mean-cj commented Jun 3, 2026

Hi @nadar,

Hope you are doing well : )

I added the getHeaders() function to allow retrieving the HTTP headers that were previously added using the setHeaders() function.

These values represent the HTTP request headers that will be sent through the cURL request.

The returned values are only the request headers and are not mixed with the ResponseHeader.

Thanks.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants