I've been working on, what should be for most users, an almost entirely backwards compatible update to Guzzle which adds the following enhancements:
1. Asynchronous future responses and makes it easier to create new adapters (e.g., curl, stream wrapper, sockets, etc). The async support works in a completely backwards compatible way to the existing synchronous workflow of Guzzle, but now provides the ability to use Guzzle with non-blocking libraries (e.g., React).
2. Compatible with the latest PSR-7 updates. If the PSR-7 proposal remains mostly unchanged, then Guzzle can later extend from the PSR-7 message interfaces in a backwards compatible way.
3. Added a new terminal "end" event to requests that is only emitted once per request, making it easier to work with only the end-result of a message (complete and error can be emitted N number of times).
This updated version of Guzzle uses a new project to manage the adapter layer to make it easier to implement custom adapters without having to know anything about the internals of Guzzle (see: http://mtdowling.com/blog/2014/09/28/guzzle-ring/).
A full list of changes can be found here: https://github.com/guzzle/guzzle/blob/ring/CHANGELOG.md#500-tbd. As you can see, for most users, this update should be a no-op.
I was hoping that if I tagged version 5 in the next few days that Drupal 8 could update to use it. The reason I think it's important that Drupal updates to this new version is that we are working on a new version of the AWS SDK for PHP that will rely on Guzzle ~5. This new version is something Drupal users are going to want to use over the previous version because it provides significant improvements is also mostly backwards compatible to its previous version. I can submit a patch to Goutte to update to version 5 (it should just be a matter of updating the composer.json file).
Please let me know what I can do to help make this happen.
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | guzzle-5.37.patch | 1.23 MB | larowlan |
| #37 | interdiff.txt | 1.34 KB | larowlan |
Comments
Comment #1
mtdowling commentedComment #2
mtdowling commentedAdded mention of "end" event.
Comment #3
berdirWow, I have a feeling that you will be at Guzzle 17 before we can release Drupal 8 ;)
Comment #4
mtdowling commentedI know, my bad :). This is a pretty minor update in terms of breaking interfaces, but provides a lot of features. The good news is that we're shipping an updated AWS SDK soon, so that will effectively prevent me from shipping any more breaking changes in Guzzle :)
Comment #5
andypostIs there a way to provide guzzle as versionable library?
Why core depends on interfaces from guzzle internals?
Comment #6
andypostIs there a way to provide guzzle as versionable library?
Why core depends on interfaces from guzzle internals?
Comment #7
catchDepending on the bc breaks we might not be able to do this, but switching to task since we need to sort it out before release.
Comment #8
mtdowling commentedI ran the unit tests under core/ and didn't get any Guzzle related failures. I did get a Pecl UUID failure, but it's unrelated:
I grepped for all instances of Guzzle in Core. I've gone through each usage, line by line, to see if they require any changes. They don't, but I found a couple things that I wanted to mention. The things I'm mentioning don't require changes, but I wanted to point them out. Here are the ue
.//core/includes/install.core.inc
> no need to change
.//core/lib/Drupal/Core/Http/Client.php
- No change needed.
- Note: it's still backwards compatible, but could be updated considering the following: Guzzle 5 now uses the CA bundle of the system by default, so defining "verify" as true is now the default.
.//core/lib/Drupal/Core/Test/EventSubscriber/HttpRequestSubscriber.php
- No change
.//core/lib/Drupal.php: * @return \GuzzleHttp\ClientInterface
- No change
.//core/modules/aggregator/src/Form/OpmlFeedAdd.php
- No change
.//core/modules/aggregator/src/Plugin/aggregator/fetcher/DefaultFetcher.php
- No change
.//core/modules/hal/src/Normalizer/FileEntityNormalizer.php
- No change needed.
- Note: (line 67) uses "$file_data = $this->httpClient->get($data['uri'][0]['value'])->getBody(TRUE);". This is a change from Guzzle 3 to 4 that was missed. You need to cast the body as a string instead of passing (true) to the getBody() method. It works fine because the body, when used as as string, is cast to a string.
.//core/modules/locale/locale.batch.inc
- No change
.//core/modules/statistics/src/Tests/StatisticsAdminTest.php
- No change
.//core/modules/statistics/src/Tests/StatisticsLoggingTest.php
- No change
.//core/modules/system/core.api.php
- No change
.//core/modules/system/system.module
- No change
.//core/modules/update/src/UpdateFetcher.php
- No change
----------
Are there other places I should look to figure out the impact of this update? How do I run the simpletest tests?
Comment #9
larowlan@mtdowling you can use core/scripts/run-tests.sh to run simpletest, but simplest way is to upload a patch here.
attached patch to see what breaks
Comment #10
larowlanComment #11
larowlannote this patch is NOT FOR COMMIT, just for review.
Obviously we don't want dev-ring and minimum stability dev.
Comment #13
larowlanso 75 fails
Comment #14
mtdowling commentedDid any of those failures fail before applying the patch? I guess I'm not sure how this change is related to some of the failures. In fact, it looks like SimpleTest is using curl directly in some places that look like they failed in this update.
Comment #15
larowlan@mtdowling no - HEAD is green (https://qa.drupal.org/8.0.x-status)
The fails relate to the update status module, which uses Guzzle to fetch json or xml from drupal.org and report security updates (not sure that the test actually does this, but that is what the module does).
The fails are 'cannot serialize closure'. So I'm guessing that is something to do with the Queue entries that are created to fetch each module update in the background. These are objects that are serialized into the {queue} table with the default queue backend.
Comment #16
larowlanComment #17
larowlanComment #18
larowlanSo this is the only core change required to support the current state of the ring branch of Guzzle (which I assume to be Guzzle 5 once merged)
Comment #20
larowlanAnd we need to cast the getBody from a stream to a string
Comment #21
andypostThat's strange... I think there should be a clean way (reusable) -
fetchProjectData()should care about data and its typeComment #22
larowlanThe difference is upstream, getBody returns a guzzle stream object which can be cast to a string.
In the current version it returns differently for empty - you need to cast it to a string before checking if empty.
Comment #23
mtdowling commentedGuzzle 5 has now been tagged.
Comment #24
larowlanour head composer.json is invalid :(
So assume we meant 5.4.13?
Comment #25
andypostThat was commited in #2267551: [meta] Deal with PHP requirement vs. Debian PHP version numbering
Comment #27
larowlanMissed updates to guzzlehttp/stream too
This should be pretty close
Comment #28
dawehnerhaha, nope :)
Do we really need this? Won't that bite us in the future when people do other updates in other packages?
Seems totally unrelated :)
Comment #29
tstoecklerWe can do "prefer-stable": true then the "minimum-stability" shouldn't hurt.
Comment #30
larowlan1 and 2 will fix. 3 some are needed, some aren't
Comment #31
larowlanFixes #28 for explanation of changes to core/modules/update/src/UpdateFetcher.php core/modules/update/src/UpdateProcessor.php see fails/comments above.
I think this is ready
Comment #34
larowlanre-roll
Comment #35
berdirI think this should be casted to a string inside UpdateFetcher::fetchProjectData(). The documentation says it returns a string and the API there is clearly wrong (there is no TRUE argument anymore to getBody()).
Comment #36
larowlangood catch
Comment #37
larowlanComment #38
jibranEverything is addressed so RTBC.
Comment #39
catchCommitted/pushed to 8.0.x, thanks!
Comment #42
kim.pepperAdded follow up #2401159: Convert instances of Guzzle getBody(TRUE) for converting instances of getBody(TRUE)
Comment #43
jhedstromAdded follow-up #2442411: Update react/promise to 2.2.0 (related only in that the library was introduced by Guzzle 5).