Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
[HttpClient] Add a ScopingHttpClient #30654
When the requested URL is a relative one, a default index can be provided - whose corresponding default options (the
Regexps are anchored on their left side.
E.g. this defines a client that will send some github token when a request is made to the corresponding API, and will not send those credentials if any other host is requested, while also turning relative URLs to github ones:
$client = HttpClient::create(); $githubClient = new ScopingClient($client, [ 'http://api\.github\.com/' => [ 'base_uri' => 'http://api.github.com/', 'headers' => ['Authorization: token '.$githubToken], ], ], 'http://api\.github\.com/');
Of course, it's possible to define several regexps as keys so that one can create a client that is authenticated against several hosts/paths.