Description
Description
Occasionally a service requires underscores in its HTTP headers. There's no way to pass them into HttpBrowser without getting replaced with hyphens, and there's no clean way to tack on an additional header to the end of the process due to the sheer number of private methods on the HttpBrowser class and its parent, AbstractBrowser.
With protected visibility, adding the extra logic for underscore'd headers for a specific use case (I agree that it doesn't need to be built into the library) is an override with a couple extra lines. Without it, implementing that functionality is close enough to impossible that I switched to Guzzle for this particular use case, because with PSR-7 requests you can specify headers and there's no transformation made in the process.
I realize there's a desire to expose as small of an API as possible, and protected methods are part of that API, but getHeaders() hasn't changed in two years, so it should be easy enough to keep that contract (Request in, array out).
Example
// override example
protected function getHeaders(Request $request)
{
$headers = parent::getHeaders($request);
if (isset($request->getServer()['api_key'])) {
$headers['api_key'] = $request->getServer()['api_key'];
}
return $headers;
}