#if HTTP_CURL_VERSION(7,14,1)
HTTP_CURL_OPT(CURLOPT_COOKIELIST, NULL);
#endif
- HTTP_CURL_OPT(CURLOPT_COOKIEFILE, NULL);
- HTTP_CURL_OPT(CURLOPT_COOKIEJAR, NULL);
HTTP_CURL_OPT(CURLOPT_RANGE, NULL);
HTTP_CURL_OPT(CURLOPT_RESUME_FROM, 0);
HTTP_CURL_OPT(CURLOPT_MAXFILESIZE, 0);
}
}
-#if HTTP_CURL_VERSION(7,14,1)
- /* reset cookies */
- if ((zoption = http_request_option(request, options, "resetcookies", IS_BOOL)) && Z_LVAL_P(zoption)) {
- HTTP_CURL_OPT(CURLOPT_COOKIELIST, "ALL");
- }
-#endif
-
/* session cookies */
if ((zoption = http_request_option(request, options, "cookiesession", IS_BOOL))) {
- if (Z_LVAL_P(zoption)) {
+ if (Z_BVAL_P(zoption)) {
/* accept cookies for this session */
HTTP_CURL_OPT(CURLOPT_COOKIEFILE, "");
} else {
- /* reset session cookies */
+ /* don't load session cookies from cookiestore */
HTTP_CURL_OPT(CURLOPT_COOKIESESSION, 1);
}
}
/* cookiestore, read initial cookies from that file and store cookies back into that file */
- if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING)) && Z_STRLEN_P(zoption)) {
- HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE);
+ if ((zoption = http_request_option(request, options, "cookiestore", IS_STRING))) {
+ if (Z_STRLEN_P(zoption)) {
+ HTTP_CHECK_OPEN_BASEDIR(Z_STRVAL_P(zoption), return FAILURE);
+ }
HTTP_CURL_OPT(CURLOPT_COOKIEFILE, Z_STRVAL_P(zoption));
HTTP_CURL_OPT(CURLOPT_COOKIEJAR, Z_STRVAL_P(zoption));
}
HTTP_ARG_VAL(cookies, 0)
HTTP_END_ARGS;
+#if HTTP_CURL_VERSION(7,14,1)
+HTTP_EMPTY_ARGS(resetCookies);
+#endif
+
HTTP_EMPTY_ARGS(getUrl);
HTTP_BEGIN_ARGS(setUrl, 1)
HTTP_ARG_VAL(url, 0)
HTTP_REQUEST_ME(addCookies, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(getCookies, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(setCookies, ZEND_ACC_PUBLIC)
+#if HTTP_CURL_VERSION(7,14,1)
+ HTTP_REQUEST_ME(resetCookies, ZEND_ACC_PUBLIC)
+#endif
HTTP_REQUEST_ME(setMethod, ZEND_ACC_PUBLIC)
HTTP_REQUEST_ME(getMethod, ZEND_ACC_PUBLIC)
efree(o);
}
+#define http_request_object_resetcookies(o) _http_request_object_resetcookies((o) TSRMLS_CC)
+static inline STATUS _http_request_object_resetcookies(zval *this_ptr TSRMLS_DC)
+{
+ getObject(http_request_object, obj);
+ return curl_easy_setopt(obj->request->ch, CURLOPT_COOKIELIST, "ALL");
+}
+
#define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
{
zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "seturl", NULL, *opt);
} else if (!strcmp(key, "method")) {
zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "setmethod", NULL, *opt);
+ } else if (!strcmp(key, "resetcookies")) {
+ http_request_object_resetcookies(getThis());
} else {
ZVAL_ADDREF(*opt);
add_assoc_zval(add_opts, key, *opt);
}
/* }}} */
+#if HTTP_CURL_VERSION(7,14,1)
+/* {{{ proto bool HttpRequest::resetCookies()
+ *
+ * Reset all cookies. Note that customly set cookies are not affected.
+ */
+PHP_METHOD(HttpRequest, resetCookies)
+{
+ NO_ARGS;
+ RETURN_SUCCESS(http_request_object_resetcookies(getThis()));
+}
+/* }}} */
+#endif
+
/* {{{ proto bool HttpRequest::setUrl(string url)
*
* Set the request URL.
PHP_METHOD(HttpRequest, addCookies);
PHP_METHOD(HttpRequest, getCookies);
PHP_METHOD(HttpRequest, setCookies);
+#if HTTP_CURL_VERSION(7,14,1)
+PHP_METHOD(HttpRequest, resetCookies);
+#endif
PHP_METHOD(HttpRequest, setMethod);
PHP_METHOD(HttpRequest, getMethod);
PHP_METHOD(HttpRequest, setUrl);
--- /dev/null
+--TEST--
+HttpRequest cookie API
+--SKIPIF--
+<?php
+include 'skip.inc';
+checkmin(5);
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+$r = new HttpRequest("http://dev.iworks.at/.cookie.php");
+$r->recordHistory = true;
+
+$r->send();
+$c[0] = $r->getResponseInfo("cookies");
+var_dump(empty($c[0]));
+
+$r->setOptions(array("cookiesession" => true));
+
+$r->send();
+$c[1] = $r->getResponseInfo("cookies");
+var_dump(empty($c[1]));
+
+$r->resetCookies();
+
+$r->send();
+$c[2] = $r->getResponseInfo("cookies");
+var_dump($c[1] === $c[2]);
+
+$r->send();
+$c[3] = $r->getResponseInfo("cookies");
+var_dump($c[2] === $c[3]);
+
+echo "Done\n";
+--EXPECTF--
+%sTEST
+bool(true)
+bool(false)
+bool(false)
+bool(true)
+Done