[wp-trac] [WordPress Trac] #9049: Support for sending and receiving
cookies in the HTTP API
WordPress Trac
wp-trac at lists.automattic.com
Thu Feb 5 01:11:03 GMT 2009
#9049: Support for sending and receiving cookies in the HTTP API
-------------------------+--------------------------------------------------
Reporter: beaulebens | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: 2.8
Component: HTTP | Version:
Severity: normal | Keywords: has-patch needs-testing
-------------------------+--------------------------------------------------
Attached is a patch for the HTTP API (wp-includes/http.php) which adds
support for sending and receiving cookies. I've also included some tests
(cookie*.php) that work in the same fashion as the "http-tests.zip"
attached to #4779 (put them in a folder called "http-tests" immediately in
the root of a WP install).
This patch supersedes/assumes #9037 to allow for handling multiple Set-
Cookie: headers which some servers send. If this gets committed then it
would also close #8727.
It works something like this:
{{{
$response = wp_remote_get( $url_that_will_send_back_cookies );
$cookies = array();
if (isset($response['cookies'])) {
$cookies = $response['cookies']; // Array of WP_Http_Cookie
objects
}
$cookies[] = new WP_Http_Cookie( array( 'name' => 'custom-cookie', 'value'
=> 'adding a manually created cookie' ) );
$response = wp_remote_get($url_that_will_accept_cookies,
array('cookies'=>$cookies));
}}}
Cookies are never written to file (unless you choose to do so yourself),
they are only maintained in memory between requests.
I have ''not'' tested the ExtHTTP (PHP 5.2+ http extension) implementation
at all yet, because I'm having trouble getting the extension installed. It
should work the same as the other transports, but it needs testing.
--
Ticket URL: <http://trac.wordpress.org/ticket/9049>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list