Skip to content
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

Networking: Swap Requests transports using the http_api_transports instead of patching the Requests library #1004

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Feb 6, 2024

Before this PR, we were patching the default WordPress transports to always return false from their test() method which, otherwise, could return a false positive. It was a hack. It solved the problem at hand, but added complexity and maintenance burden.

This PR removes the patching and instead swaps the Requests transports from within the Playground my-plugin using the http_api_transports WordPress filter.

Testing instructions

Confirm the CI checks pass

cc @bgrgicak

…stead of patching the Requests library.

Before this PR, we were patching the default WordPress transports to
always return `false` from their `test()` method which, otherwise,
could return a false positive. It was a hack. It solved the problem at hand,
but added complexity and maintenance burden.

This PR removes the patching and instead swaps the Requests transports
from within the Playground my-plugin using the `http_api_transports`
WordPress filter.

 ## Testing instructions

Confirm the CI checks pass

cc @bgrgicak
@adamziel adamziel merged commit 5e0508f into trunk Feb 6, 2024
5 checks passed
@adamziel adamziel deleted the dont-patch-requests-transports branch February 6, 2024 10:07
adamziel added a commit that referenced this pull request Feb 6, 2024
Installs the Playground mu-plugin even when WordPress is loaded
from the OPFS to ensure:

* The mu-plugin is always there, even when a custom WordPress directory
  is mounted.
* The mu-plugin is always up to date.

Depends on #1004

## Testing instructions

Confirm the CI checks pass
adamziel added a commit that referenced this pull request Feb 22, 2024
The recent [removal of custom WordPress
patches](#1004)
broke the networking feature when the extra PHP extensions are enabled.
It removed the default networking tranports via the http_api_transports
filter, but it did not account for WordPress trying to use the Fetch and
Fsockopen transports anyway whenever their `::test()` method returns
true – which it does when the OpenSSL extension is available.

This PR uses the reflections API to force-replace the
Requests::$transports array with one containing exclusively the Fetch
transport.

Open Playground, enable PHP extensions and networking, go to WP Admin >
Plugins > Add, confirm the list of plugins is visible

CC @bgrgicak @annezazu
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.

1 participant