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

Customizing HTTP arguments for all requests #783

Closed
pawelkmpt opened this issue Apr 4, 2019 · 7 comments
Closed

Customizing HTTP arguments for all requests #783

pawelkmpt opened this issue Apr 4, 2019 · 7 comments

Comments

@pawelkmpt
Copy link

I wanted to ask why this plugin appends HTTP arguments for all requests (or at least requests in custom WP-CLI commands)? It'd be better to add it only when GitHub Updater actions are performed.

Current behavior breaks my plugin in which I need custom user agent and skip SSL verification.

@afragen
Copy link
Owner

afragen commented Apr 4, 2019

Can you give me an example of this?

@pawelkmpt
Copy link
Author

I use wp_remote_post() and wp_remote_get() to perform requests and customize them with passing array of arguments to these functions, eg.

$args = [
    'timeout'    => 180,
    'user-agent' => 'my-plugin-name/WP-CLI',
    'sslverify'  => false,
];

$response = wp_remote_post( $url, $args );

When GitHub Updater is network activated, request arguments look like this:

[
    "user-agent" => "my-plugin-name/WP-CLI; GitHub Updater - https://github.com/afragen/github-updater",
    "sslverify"  => true
]

Your plugin appends changes using http_request_args filter which overrides my customizations.

@afragen
Copy link
Owner

afragen commented Apr 4, 2019

I was asked several years ago by someone at GitHub to add a header specifically identifying GHU.

Just as I use the http_request_args filter to add these you can use it to remove them. Simply call the filter at a higher priority like 15.

@afragen afragen closed this as completed Apr 4, 2019
@pawelkmpt
Copy link
Author

I was asked several years ago by someone at GitHub to add a header specifically identifying GHU.

That's understandable, but it affects whole WordPress installation.

Just as I use the http_request_args filter to add these you can use it to remove them. Simply call the filter at a higher priority like 15.

I'm aware I can remove it, but it's not a perfect solution to have to think about removing hooks for every plugin which uses wp_remote_*() functions

@afragen
Copy link
Owner

afragen commented Apr 4, 2019

GitHub GET requests are on HTTPS. If your plugin makes different requests you can filter based upon the URL as it is passed in the filter.

I’m on mobile today. But I’ll look to see if I don’t/can’t remove this filter after it’s used.

@afragen afragen reopened this Apr 4, 2019
@afragen afragen closed this as completed in 6b0eb3a Apr 5, 2019
@afragen
Copy link
Owner

afragen commented Apr 5, 2019

@pawelkmpt can you test and confirm this fix? Thanks.

@pawelkmpt
Copy link
Author

@afragen yes, it's fine now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants