#37503 closed defect (bug) (fixed)
Requests doesn't pass through custom methods in cURL transport
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.6 | Priority: | normal |
Severity: | normal | Version: | 4.6 |
Component: | HTTP API | Keywords: | upstream has-patch commit |
Focuses: | Cc: |
Description
Passing custom methods through wp_remote_request is defaulting to GET instead of whatever the method actually is.
This code:
$response = wp_remote_request($purgeme, array('method' => 'PURGE', 'headers' => array( 'host' => $p['host'], 'X-Purge-Method' => $varnish_x_purgemethod ) ) );
Would output a GET instead of a PURGE for example. It's a method used by quite a lot of Varnish related plugins and would break caching for them. Or rather, it would make caching stop flushing. (There's a saving water in California joke in there somewhere.)
Thanks to @ocean90 for pointing out that this:
was missing the defaults found here:
Attached is a patch that adds a default back. If I use a method of PURGE, PURGE is sent. If I do not specify a method, GET is sent.
Looking at it, perhaps lines 336-342 could be removed, as that is the same as the default?
Attachments (3)
Change History (15)
#1
@
7 years ago
- Keywords upstream added
- Milestone changed from Awaiting Review to 4.6
- Owner set to rmccue
- Status changed from new to reviewing
Created a pull request as well: https://github.com/rmccue/Requests/pull/227/
If this doesn't get accepted for some reasons we might have to look at the existing hooks, like curl.before_request
. Sadly those don't provide any context.
#2
@
7 years ago
- Summary changed from Request API doesn't pass through custom methods to Requests doesn't pass through custom methods in cURL transport
#4
@
7 years ago
- Owner changed from rmccue to dd32
37503.2.patch removes the case for PATCH, PUT, DELETE and OPTIONS since it's the same as the default case.
I'm unsure if we need a check for the $data
value here. It was previously wrapped with a is_null()
condition. From the API documentation:
If CURLOPT_POSTFIELDS is explicitly set to NULL then libcurl will get the POST data from the read callback. If you want to send a zero-byte POST set CURLOPT_POSTFIELDS to an empty string, or set CURLOPT_POST to 1 and CURLOPT_POSTFIELDSIZE to 0.
— https://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDS.html
@dd32 What do you think about this? Would like to have this for RC2.
#7
@
7 years ago
Patch refreshed for https://github.com/rmccue/Requests/pull/227#issuecomment-237212857.
Adding in a default to the CURL calls