Skip to content

Commit cc1f8c5

Browse files
authored
Composer v2.9 compatibility (#22)
Hack to disallow HTTP/3, forcing `HttpDownloader` to use `RemoteFilesystem` instead of `CurlDownloader`. I suspect api.wordpress.org does not properly support HTTP/3: $ curl --http1.1 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision' ...json response $ curl --http2 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision' ...json response $ curl --http3-only 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision' ...sometimes json response ...but most of the time ERR_DRAINING curl: (56) ngtcp2_conn_writev_stream returned error: ERR_DRAINING See: - composer/composer#12363 - https://github.com/composer/composer/blob/f5854b140ca27164d352ce30deece798acf3e36b/src/Composer/Util/HttpDownloader.php#L537
1 parent dd991b3 commit cc1f8c5

File tree

10 files changed

+64
-8
lines changed

10 files changed

+64
-8
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
strategy:
104104
matrix:
105105
php-version: ${{ fromJSON(needs.php-matrix.outputs.versions) }}
106-
composer-version: ['2.6', '2.7', '2.8']
106+
composer-version: ['2.6', '2.7', '2.8', '2.9']
107107
runs-on: ubuntu-latest
108108
env:
109109
GOFLAGS: '-mod=mod'

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
export GOFLAGS=-mod=mod
22

33
combos := php-8-composer-latest \
4+
php-8.4-composer-2.9 \
45
php-8.4-composer-2.8 \
56
php-8.4-composer-2.7 \
67
php-8.4-composer-2.6 \
8+
php-8.3-composer-2.9 \
79
php-8.3-composer-2.8 \
810
php-8.3-composer-2.7 \
911
php-8.3-composer-2.6

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,40 @@ If you must clear the cache, delete the `<composer-cache-dir>/wp-org-closed-plug
161161
rm -rf $(composer config cache-dir)/wp-org-closed-plugin
162162
```
163163

164+
### Why `allow_self_signed` when connecting to `https://api.wordpress.org`?
165+
166+
> [!IMPORTANT]
167+
> **Help Wanted!**
168+
>
169+
> Please send pull requests if you know how to get around the error:
170+
>
171+
> ```console
172+
> $ curl --http3-only 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
173+
> curl: (56) ngtcp2_conn_writev_stream returned error: ERR_DRAINING
174+
> ```
175+
176+
It is a hack to disallow HTTP/3, forcing `HttpDownloader` to use `RemoteFilesystem` instead of `CurlDownloader`.
177+
178+
I suspect api.wordpress.org does not properly support HTTP/3:
179+
180+
```console
181+
$ curl --http1.1 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
182+
...json response
183+
184+
$ curl --http2 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
185+
...json response
186+
187+
$ curl --http3-only 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
188+
...sometimes json response
189+
...but most of the time ERR_DRAINING
190+
curl: (56) ngtcp2_conn_writev_stream returned error: ERR_DRAINING
191+
```
192+
193+
See:
194+
- https://github.com/composer/composer/pull/12363
195+
- https://github.com/composer/composer/blob/f5854b140ca27164d352ce30deece798acf3e36b/src/Composer/Util/HttpDownloader.php#L537
196+
- https://github.com/typisttech/wp-org-closed-plugin/pull/22
197+
164198
> [!TIP]
165199
> **Hire Tang Rufus!**
166200
>

src/WpOrg/Api/Client.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@
1212

1313
readonly class Client
1414
{
15+
/**
16+
* Hack to disallow HTTP/3, forcing HttpDownloader to use RemoteFilesystem instead of CurlDownloader.
17+
*
18+
* I suspect api.wordpress.org does not properly support HTTP/3:
19+
*
20+
* $ curl --http1.1 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
21+
* ...json response
22+
*
23+
* $ curl --http2 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
24+
* ...json response
25+
*
26+
* $ curl --http3-only 'https://api.wordpress.org/plugins/info/1.2/?action=plugin_information&slug=better-delete-revision'
27+
* ...sometimes json response
28+
* ...but most of the time ERR_DRAINING
29+
* curl: (56) ngtcp2_conn_writev_stream returned error: ERR_DRAINING
30+
*
31+
* See:
32+
* - https://github.com/composer/composer/pull/12363
33+
* - https://github.com/composer/composer/blob/f5854b140ca27164d352ce30deece798acf3e36b/src/Composer/Util/HttpDownloader.php#L537
34+
*/
35+
private const OPTIONS = [
36+
'ssl' => [
37+
'allow_self_signed' => true,
38+
],
39+
];
40+
1541
public function __construct(
1642
private HttpDownloader $httpDownloader,
1743
private Loop $loop,
@@ -88,7 +114,7 @@ private function fetchAsync(string $slug): PromiseInterface
88114
], '', '&'),
89115
);
90116

91-
return $this->httpDownloader->add($url)
117+
return $this->httpDownloader->add($url, self::OPTIONS)
92118
->then(static fn () => null) // Ignore successful responses. Closed plugins always return 404.
93119
->catch(static function (TransportException $e): ?string {
94120
// Closed plugins always return 404.

testdata/script/install_dist_closed.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
66

77
exec composer install
88

9-
stderr 'Nothing to install, update or remove'
109
stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
1110

1211
-- composer.json --

testdata/script/install_dist_open.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exec composer install
66

77
exec composer install
88

9-
stderr 'Nothing to install, update or remove'
109
! stderr abandoned
1110

1211
-- composer.json --

testdata/script/require_dist_closed.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
66

77
exec composer require wpackagist-plugin/better-delete-revision
88

9-
stderr 'Nothing to install, update or remove'
109
stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
1110

1211
-- composer.json --

testdata/script/require_dist_open.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exec composer require wpackagist-plugin/hello-dolly
66

77
exec composer require wpackagist-plugin/hello-dolly
88

9-
stderr 'Nothing to install, update or remove'
109
! stderr abandoned
1110

1211
-- composer.json --

testdata/script/update_dist_closed.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
66

77
exec composer update
88

9-
stderr 'Nothing to install, update or remove'
109
stderr -count=1 'Package wpackagist-plugin/better-delete-revision is abandoned'
1110

1211
-- composer.json --

testdata/script/update_dist_open.txtar

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ exec composer update
66

77
exec composer update
88

9-
stderr 'Nothing to install, update or remove'
109
! stderr abandoned
1110

1211
-- composer.json --

0 commit comments

Comments
 (0)