8000 Change HttpBrowser::getHeaders() method visibility to protected from private · Issue #38051 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Change HttpBrowser::getHeaders() method visibility to protected from private #38051
Closed
@iansltx

Description

@iansltx

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;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0