FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Small Enhancement (http header capitalization) #346

Open sbreiler opened 6 years ago

sbreiler commented 6 years ago

Hi,

while, technical speaking, the header capitalization doesn't matter, i would like to have the option to have a camel-case-styled headers send to the server. I'd love to have the requests as browser-like as possible.

Example 1 ("bad" aka "what you get now at version 3.2"): accept-encoding: gzip, deflate

Example 2 ("good"): Accept-Encoding: gzip, deflate

I made myself a simple helper function to aquire this:

protected function convertHeaderFieldNameToCamelCase($input) {
    return mb_convert_case($input, MB_CASE_TITLE, "UTF-8");
}

This function should be called in https://github.com/FriendsOfPHP/Goutte/blob/master/Goutte/Client.php#L152 Something like:

if( true === is_array($requestOptions['headers']) ) {
    $tmp_headers = array();
    foreach ($requestOptions['headers'] as $name => $value) {
        $tmp_headers[$this->convertHeaderFieldNameToCamelCase($name)] = $value;
    }
    $requestOptions['headers'] = $tmp_headers;
    unset($tmp_headers);
}

I can provide a PR, if you want.

fabpot commented 6 years ago

As you said, it does not matter. So, not something we need to fix.