X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=http_request_object.c;h=9bebb438b7f1e1cf8f8bf35f7c95f3f31e1e7948;hp=76ba2dd1d2eefc300562f16796701f3c7c9e1ae9;hb=d4738dfa25feeba82269ac47f7f4b3054da7fe42;hpb=8cba9d81560b60079a53241b3f906e9dff50196e diff --git a/http_request_object.c b/http_request_object.c index 76ba2dd..9bebb43 100644 --- a/http_request_object.c +++ b/http_request_object.c @@ -12,33 +12,25 @@ /* $Id$ */ - #ifdef HAVE_CONFIG_H # include "config.h" #endif -#include "php.h" + +#define HTTP_WANT_CURL +#include "php_http.h" #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL) #include "zend_interfaces.h" -#include "php_http_std_defs.h" -#include "php_http_request_object.h" -#include "php_http_request_api.h" -#include "php_http_request_pool_api.h" -#include "php_http.h" #include "php_http_api.h" -#include "php_http_url_api.h" +#include "php_http_exception_object.h" #include "php_http_message_api.h" #include "php_http_message_object.h" -#include "php_http_exception_object.h" - -#include "missing.h" - -#ifdef PHP_WIN32 -# include -#endif -#include +#include "php_http_request_api.h" +#include "php_http_request_object.h" +#include "php_http_request_pool_api.h" +#include "php_http_url_api.h" ZEND_EXTERN_MODULE_GLOBALS(http); @@ -778,6 +770,7 @@ PHP_METHOD(HttpRequest, setOptions) { char *key = NULL; ulong idx = 0; + HashPosition pos; zval *opts = NULL, *old_opts, **opt; getObject(http_request_object, obj); @@ -795,7 +788,7 @@ PHP_METHOD(HttpRequest, setOptions) } /* some options need extra attention -- thus cannot use array_merge() directly */ - FOREACH_KEYVAL(opts, key, idx, opt) { + FOREACH_KEYVAL(pos, opts, key, idx, opt) { if (key) { if (!strcmp(key, "headers")) { zval **headers; @@ -1044,7 +1037,7 @@ PHP_METHOD(HttpRequest, getUrl) * Set the request method. * * Expects an int as parameter specifying the request method to use. - * In PHP 5.1+ HttpRequest::METH, otherwise the HTTP_METH constants can be used. + * In PHP 5.1+ HttpRequest::METH_*, otherwise the HTTP_METH_* constants can be used. * * Returns TRUE on success, or FALSE on failure. */ @@ -1664,15 +1657,17 @@ PHP_METHOD(HttpRequest, getResponseCookie) ulong idx = 0; char *key = NULL; zval **header = NULL; + HashPosition pos1; - convert_to_array_ex(headers); - FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers), key, idx, header) { + convert_to_array(*headers); + FOREACH_HASH_KEYVAL(pos1, Z_ARRVAL_PP(headers), key, idx, header) { if (key && !strcasecmp(key, "Set-Cookie")) { /* several cookies? */ if (Z_TYPE_PP(header) == IS_ARRAY) { zval **cookie; + HashPosition pos2; - FOREACH_HASH_VAL(Z_ARRVAL_PP(header), cookie) { + FOREACH_HASH_VAL(pos2, Z_ARRVAL_PP(header), cookie) { zval *cookie_hash; MAKE_STD_ZVAL(cookie_hash); array_init(cookie_hash); @@ -1874,6 +1869,13 @@ PHP_METHOD(HttpRequest, getResponseMessage) * references the last received response. Use HttpMessage::getParentMessage() * to access the data of previously sent requests whithin this request * cycle. + * + * Note that the internal request message is immutable, that means that the + * request message received through HttpRequest::getRequestMessage() will + * always look the same for the same request, regardless of any changes you + * may have made to the returned object. + * + * Throws HttpMalformedHeadersException, HttpEncodingException. */ PHP_METHOD(HttpRequest, getRequestMessage) { @@ -1884,8 +1886,8 @@ PHP_METHOD(HttpRequest, getRequestMessage) getObject(http_request_object, obj); SET_EH_THROW_HTTP(); - if (msg = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request))) { - RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL)); + if ((msg = http_message_parse(PHPSTR_VAL(&obj->request), PHPSTR_LEN(&obj->request)))) { + ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL)); } SET_EH_NORMAL(); } @@ -1905,7 +1907,11 @@ PHP_METHOD(HttpRequest, getRequestMessage) * The object references the last received response, use HttpMessage::getParentMessage() * to access the data of previously sent requests and received responses. * - * Throws HttpMalformedHeaderException. + * Note that the internal history is immutable, that means that any changes + * you make the the message list won't affect a history message list newly + * created by another call to HttpRequest::getHistory(). + * + * Throws HttpMalformedHeaderException, HttpEncodingException. */ PHP_METHOD(HttpRequest, getHistory) { @@ -1916,8 +1922,8 @@ PHP_METHOD(HttpRequest, getHistory) getObject(http_request_object, obj); SET_EH_THROW_HTTP(); - if (msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history))) { - RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce, msg, NULL)); + if ((msg = http_message_parse(PHPSTR_VAL(&obj->history), PHPSTR_LEN(&obj->history)))) { + ZVAL_OBJVAL(return_value, http_message_object_new_ex(http_message_object_ce, msg, NULL)); } SET_EH_NORMAL(); } @@ -1943,13 +1949,17 @@ PHP_METHOD(HttpRequest, clearHistory) * * Returns the received response as HttpMessage object. * + * NOTE: While an exception may be thrown, the transfer could have succeeded + * at least partially, so you might want to check the return values of various + * HttpRequest::getResponse*() methods. + * * Throws HttpRuntimeException, HttpRequestException, * HttpMalformedHeaderException, HttpEncodingException. * * GET example: *
  * setOptions(array('lastmodified' => filemtime('local.rss')));
  * $r->addQueryData(array('category' => 3));
  * try {
@@ -1966,7 +1976,7 @@ PHP_METHOD(HttpRequest, clearHistory)
  * POST example:
  * 
  * setOptions(array('cookies' => array('lang' => 'de')));
  * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
  * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');