/* $Id$ */
-#define _WINSOCKAPI_
-#define ZEND_INCLUDE_FULL_WINDOWS_HEADERS
-
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
}
/* }}} */
+/* {{{ proto void HTTPi_Request::unsetOptions()
+ *
+ * Unset all options/headers/cookies.
+ */
+PHP_METHOD(HTTPi_Request, unsetOptions)
+{
+ getObject(httpi_request_object, obj);
+
+ NO_ARGS;
+
+ FREE_PARR(obj, options);
+ INIT_PARR(obj, options);
+}
+/* }}} */
+
+/* {{{ proto bool HTTPi_Request::addHeader(array header)
+ *
+ * Add (a) request header name/value pair(s).
+ */
+PHP_METHOD(HTTPi_Request, addHeader)
+{
+ zval *opts, **headers, *new_headers;
+ getObject(httpi_request_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &new_headers)) {
+ RETURN_FALSE;
+ }
+
+ opts = GET_PROP(obj, options);
+
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) {
+ array_merge(new_headers, *headers);
+ } else {
+ zval_add_ref(&new_headers);
+ add_assoc_zval(opts, "headers", new_headers);
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto bool HTTPi_Request::addCookie(array cookie)
+ *
+ * Add (a) cookie(s).
+ */
+PHP_METHOD(HTTPi_Request, addCookie)
+{
+ zval *opts, **cookies, *new_cookies;
+ getObject(httpi_request_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/", &new_cookies)) {
+ RETURN_FALSE;
+ }
+
+ opts = GET_PROP(obj, options);
+
+ if (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "cookies", sizeof("cookies"), (void **) &cookies)) {
+ array_merge(new_cookies, *cookies);
+ } else {
+ zval_add_ref(&new_cookies);
+ add_assoc_zval(opts, "cookies", new_cookies);
+ }
+
+ RETURN_TRUE;
+}
+/* }}} */
+
/* {{{ proto bool HTTPi_Request::setURL(string url)
*
* Set the request URL.
/* {{{ proto array HTTPi_Request::getResponseData()
*
- * Get all resposonse data after the request has been sent.
+ * Get all response data after the request has been sent.
*/
PHP_METHOD(HTTPi_Request, getResponseData)
{
char *header_name = NULL;
int header_len = 0;
getObject(httpi_response_object, obj);
-
+
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
RETURN_FALSE;
}
-
+
data = GET_PROP(obj, responseData);
if (SUCCESS != zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &headers)) {
RETURN_FALSE;
}
-
+
if (!header_len || !header_name) {
array_init(return_value);
array_copy(*headers, return_value);
{
zval **code, **hdrs, *data;
getObject(httpi_request_object, obj);
-
+
NO_ARGS;
-
+
data = GET_PROP(obj, responseData);
if ( (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &hdrs)) &&
(SUCCESS == zend_hash_find(Z_ARRVAL_PP(hdrs), "Status", sizeof("Status"), (void **) &code))) {
}
info = GET_PROP(obj, responseInfo);
-
+
if (info_len && info_name) {
if (SUCCESS == zend_hash_find(Z_ARRVAL_P(info), pretty_key(info_name, info_len, 0, 0), info_len + 1, (void **) &infop)) {
RETURN_ZVAL(*infop, 1, ZVAL_PTR_DTOR);
/* {{{ proto bool HTTPi_Request::send()
*
* Send the HTTP request.
+ *
+ * GET example:
+ * <pre>
+ * <?php
+ * $r = new HTTPi_Request('http://example.com/feed.rss', HTTP_GET);
+ * $r->setOptions(array('lastmodified' => filemtime('local.rss')));
+ * $r->addQueryData(array('category' => 3));
+ * if ($r->send() && $r->getResponseCode() == 200) {
+ * file_put_contents('local.rss', $r->getResponseBody());
+ * }
+ * ?>
+ * </pre>
+ *
+ * POST example:
+ * <pre>
+ * <?php
+ * $r = new HTTPi_Request('http://example.com/form.php', HTTP_POST);
+ * $r->setOptions(array('cookies' => array('lang' => 'de')));
+ * $r->addPostData(array('user' => 'mike', 'pass' => 's3c|r3t'));
+ * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
+ * if ($r->send()) {
+ * echo $r->getResponseBody();
+ * }
+ * ?>
+ * </pre>
*/
PHP_METHOD(HTTPi_Request, send)
{