1. 22 Mar, 2022 1 commit
  2. 28 Apr, 2019 1 commit
  3. 12 Apr, 2019 1 commit
    • Fabien Potencier's avatar
      bug #30967 [HttpClient] Document the state object that is passed around by the... · 66327bd1
      Fabien Potencier authored
      bug #30967 [HttpClient] Document the state object that is passed around by the HttpClient (derrabus)
      
      This PR was merged into the 4.3-dev branch.
      
      Discussion
      ----------
      
      [HttpClient] Document the state object that is passed around by the HttpClient
      
      | Q             | A
      | ------------- | ---
      | Branch?       | master
      | Bug fix?      | yes
      | New feature?  | no
      | BC breaks?    | no
      | Deprecations? | no
      | Tests pass?   | yes
      | Fixed tickets | N/A
      | License       | MIT
      | Doc PR        | N/A
      
      In an attempt to make the code of the new HttpClient component more understandable, I've introduced internal classes that document the `$multi` object that is being passed around between *Client and *Response classes.
      
      My goal is to make the code more accessible to potential contributors and static code analyzers.
      
      Commits
      -------
      
      20f4eb3204 Document the state object that is passed around by the HttpClient.
      66327bd1
  4. 11 Apr, 2019 1 commit
  5. 10 Apr, 2019 2 commits
  6. 09 Apr, 2019 2 commits
  7. 08 Apr, 2019 2 commits
  8. 06 Apr, 2019 2 commits
  9. 05 Apr, 2019 2 commits
  10. 04 Apr, 2019 1 commit
  11. 03 Apr, 2019 3 commits
  12. 02 Apr, 2019 1 commit
  13. 28 Mar, 2019 4 commits
  14. 26 Mar, 2019 1 commit
  15. 24 Mar, 2019 2 commits
  16. 23 Mar, 2019 4 commits
    • Fabien Potencier's avatar
      fixed CS · ba79f620
      Fabien Potencier authored
      ba79f620
    • Fabien Potencier's avatar
      feature #30629 [HttpClient] added CachingHttpClient (fabpot) · 2d44efdc
      Fabien Potencier authored
      This PR was merged into the 4.3-dev branch.
      
      Discussion
      ----------
      
      [HttpClient] added CachingHttpClient
      
      | Q             | A
      | ------------- | ---
      | Branch?       | master
      | Bug fix?      | no
      | New feature?  | yes
      | BC breaks?    | no
      | Deprecations? | no
      | Tests pass?   | yes
      | Fixed tickets | -
      | License       | MIT
      | Doc PR        | -
      
      The proposed `CachingHttpClient` uses `HttpCache` from the HttpKernel component to provide an HTTP-compliant cache.
      
      If this is accepted, it could replace the corresponding part in #30602
      
      Commits
      -------
      
      dae5686722 [HttpClient] added CachingHttpClient
      2d44efdc
    • Fabien Potencier's avatar
      feature #30602 [BrowserKit] Add support for HttpClient (fabpot, THERAGE Kévin) · 95601ec4
      Fabien Potencier authored
      This PR was merged into the 4.3-dev branch.
      
      Discussion
      ----------
      
      [BrowserKit] Add support for HttpClient
      
      | Q             | A
      | ------------- | ---
      | Branch?       | master
      | Bug fix?      | no
      | New feature?  | yes
      | BC breaks?    | no
      | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
      | Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
      | Fixed tickets | part of #30502
      | License       | MIT
      | Doc PR        | not yet
      
      When combining the power of the new HttpClient component with the BrowserKit and Mime components, we can makes something really powerful... a full/better/awesome replacement for https://github.com/FriendsOfPHP/Goutte.
      
      So, this PR is about integrating the HttpClient component with BrowserKit to give users a high-level interface to ease usages in the most common use cases.
      
      Scraping websites can be done like this:
      
      ```php
      use Symfony\Component\BrowserKit\HttpBrowser;
      use Symfony\Component\HttpClient\HttpClient;
      
      $client = HttpClient::create();
      $browser = new HttpBrowser($client);
      
      $browser->request('GET', 'https://example.com/');
      $browser->clickLink('Log In');
      $browser->submitForm('Sign In', ['username' => 'me', 'password' => 'pass']);
      $browser->clickLink('Subscriptions')->filter('table tr:nth-child(2) td:nth-child(2)')->each(function ($node) {
          echo trim($node->text())."\n";
      });
      ```
      
      And voilà! Nice, isn't?
      
      Want to add HTTP cache? Sure:
      
      ```php
      use Symfony\Component\HttpKernel\HttpCache\Store;
      
      $client = HttpClient::create();
      $store = new Store(sys_get_temp_dir().'/http-cache-store');
      
      $browser = new HttpBrowser($client, $store);
      
      // ...
      ```
      
      Want logging and debugging of HTTP Cache? Yep:
      
      ```php
      use Psr\Log\AbstractLogger;
      
      class EchoLogger extends AbstractLogger
      {
          public function log($level, $message, array $context = [])
          {
              echo $message."\n";
          }
      }
      
      $browser = new HttpBrowser($client, $store, new EchoLogger());
      ```
      
      The first time you run your code, you will get an output similar to:
      
      ```
      Request: GET https://twig.symfony.com/
      Response: 200 https://twig.symfony.com/
      Cache: GET /: miss, store
      Request: GET https://twig.symfony.com/doc/2.x/
      Response: 200 https://twig.symfony.com/doc/2.x/
      Cache: GET /doc/2.x/: miss, store
      ```
      
      But then:
      
      ```
      Cache: GET /: fresh
      Cache: GET /doc/2.x/: fresh
      ```
      
      Limit is the sky here as you get the full power of all the Symfony ecosystem.
      
      Under the hood, these examples leverage HttpFoundation, HttpKernel (with HttpCache),
      DomCrawler, BrowserKit, CssSelector, HttpClient, Mime, ...
      
      Excited?
      
      P.S. : Tests need to wait for the HttpClient Mock class to land into master.
      
      Commits
      -------
      
      b5b2a2557c Add tests for HttpBrowser
      dd55845706 [BrowserKit] added support for HttpClient
      95601ec4
    • Anthony MARTIN's avatar
      [HttpClient] Add a ScopingHttpClient · 6f18bd47
      Anthony MARTIN authored
      6f18bd47
  17. 22 Mar, 2019 2 commits
  18. 21 Mar, 2019 1 commit
  19. 19 Mar, 2019 4 commits
    • Fabien Potencier's avatar
      feature #30604 [HttpClient] add MockHttpClient (nicolas-grekas) · 25c4d9f9
      Fabien Potencier authored
      This PR was merged into the 4.3-dev branch.
      
      Discussion
      ----------
      
      [HttpClient] add 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 PR introduces `MockHttpClient` and `MockResponse`, to be used for testing classes that need an HTTP client without making actual HTTP requests.
      
      `MockHttpClient` is configured via its constructor: you provide it either with an iterable or a callable, and these will be used to provide responses as the consumer requests them.
      
      Example:
      ```php
      $responses = [
          new MockResponse($body1, $info1),
          new MockResponse($body2, $info2),
      ];
      
      $client = new MockHttpClient($responses);
      $response1 = $client->request(...); // created from $responses[0]
      $response2 = $client->request(...); // created from $responses[1]
      ```
      
      Or alternatively:
      ```php
      $callback = function ($method, $url, $options) {
          return new MockResponse(...);
      };
      
      $client = new MockHttpClient($callback);
      $response = $client->request(...); // calls $callback internal
      ```
      
      The responses provided to the client don't have to be instances of `MockResponse` - any `ResponseInterface` works (e.g. `$this->getMockBuilder(ResponseInterface::class)->getMock()`).
      
      Using `MockResponse` allows simulating chunked responses and timeouts:
      ```php
      $body = function () {
          yield 'hello';
          yield ''; // the empty string is turned into a timeout so that they are easy to test
          yield 'world';
      };
      $mockResponse = new Mockresponse($body);
      ```
      
      Last but not least, the implementation simulates the full lifecycle of a properly behaving `HttpClientInterface` contracts implementation: error handling, progress function, etc. This is "proved" by `MockHttpClientTest`, who implements and passes the reference test suite in `HttpClientTestCase`.
      
      Commits
      -------
      
      8fd7584158 [HttpClient] add MockHttpClient
      25c4d9f9
    • Nicolas Grekas's avatar
      [HttpClient] add MockHttpClient · bf484547
      Nicolas Grekas authored
      bf484547
    • Fabien Potencier's avatar
      feature #30567 [HttpClient] exceptions carry response (antonch1989) · 834f8c8b
      Fabien Potencier authored
      This PR was squashed before being merged into the 4.3-dev branch (closes #30567).
      
      Discussion
      ----------
      
      [HttpClient] exceptions carry response
      
      | Q             | A
      | ------------- | ---
      | Branch?       | master
      | Bug fix?      | no
      | New feature?  | yes
      | BC breaks?    | no     <!-- see https://symfony.com/bc -->
      | Deprecations? | no
      | Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
      | Fixed tickets | #30502
      | License       | MIT
      | Doc PR        |
      
      Commits
      -------
      
      103448cc67 [HttpClient] exceptions carry response
      834f8c8b
    • Anton Chernikov's avatar
      [HttpClient] exceptions carry response · 38189971
      Anton Chernikov authored
      38189971
  20. 18 Mar, 2019 1 commit
  21. 17 Mar, 2019 2 commits
    • Thomas Talbot's avatar
    • Fabien Potencier's avatar
      minor #30549 [HttpClient] Make exceptions public (dunglas) · 86f3126f
      Fabien Potencier authored
      This PR was squashed before being merged into the 4.3-dev branch (closes #30549).
      
      Discussion
      ----------
      
      [HttpClient] Make exceptions public
      
      | Q             | A
      | ------------- | ---
      | Branch?       | master
      | Bug fix?      | no
      | New feature?  | no<!-- don't forget to update src/**/CHANGELOG.md files -->
      | BC breaks?    | no     <!-- see https://symfony.com/bc -->
      | Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
      | Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
      | Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
      | License       | MIT
      | Doc PR        | n/a
      
      Makes it easier to implement the interface. See api-platform/core#2608
      
      Commits
      -------
      
      928d774e4a [HttpClient] Make exceptions public
      86f3126f