Skip to content

[HttpClient] Add ScopingHttpClient::forBaseUri() + tweak MockHttpClient #30843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 3, 2019

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Apr 3, 2019

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This allows creating scoped HTTP clients in one line:

$client = ScopingHttpClient::forBaseUri($client, 'http://example.com');

$client now resolves relative URLs using the provided base URI.

If one also adds default options as 3rd argument, these will be applied conditionally when a URL matching the base URI is requested.

This PR also tweaks MockHttpClient to make it return MockResponse on its own when no constructor argument is provided, easing tests a bit.

@fabpot
Copy link
Member

fabpot commented Apr 3, 2019

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 2b9b8e5 into symfony:master Apr 3, 2019
fabpot added a commit that referenced this pull request Apr 3, 2019
…ak MockHttpClient (nicolas-grekas)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[HttpClient] Add ScopingHttpClient::forBaseUri() + tweak MockHttpClient

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This allows creating scoped HTTP clients in one line:

```php
$client = ScopingHttpClient::forBaseUri($client, 'http://example.com');
```

`$client` now resolves relative URLs using the provided base URI.

If one also adds default options as 3rd argument, these will be applied conditionally when a URL matching the base URI is requested.

This PR also tweaks `MockHttpClient` to make it return `MockResponse` on its own when no constructor argument is provided, easing tests a bit.

Commits
-------

2b9b8e5 [HttpClient] Add ScopingHttpClient::forBaseUri() + tweak MockHttpClient
@nicolas-grekas nicolas-grekas deleted the hc-forbaseuri branch April 12, 2019 12:28
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
@fabpot fabpot mentioned this pull request May 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants