2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
24 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
26 #include "php_http_std_defs.h"
27 #include "php_http_request_object.h"
28 #include "php_http_request_api.h"
29 #include "php_http_request_pool_api.h"
31 #include "php_http_api.h"
32 #include "php_http_url_api.h"
33 #include "php_http_message_api.h"
34 #include "php_http_message_object.h"
35 #include "php_http_exception_object.h"
40 # include <winsock2.h>
42 #include <curl/curl.h>
44 ZEND_EXTERN_MODULE_GLOBALS(http
);
46 #define HTTP_BEGIN_ARGS(method, ret_ref, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, ret_ref, req_args)
47 #define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpRequest, method, ret_ref)
48 #define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
49 #define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
51 HTTP_EMPTY_ARGS(__destruct
, 0);
52 HTTP_BEGIN_ARGS(__construct
, 0, 0)
54 HTTP_ARG_VAL(method
, 0)
57 HTTP_EMPTY_ARGS(getOptions
, 0);
58 HTTP_BEGIN_ARGS(setOptions
, 0, 0)
59 HTTP_ARG_VAL(options
, 0)
62 HTTP_EMPTY_ARGS(getSslOptions
, 0);
63 HTTP_BEGIN_ARGS(setSslOptions
, 0, 0)
64 HTTP_ARG_VAL(ssl_options
, 0)
67 HTTP_EMPTY_ARGS(getHeaders
, 0);
68 HTTP_BEGIN_ARGS(setHeaders
, 0, 0)
69 HTTP_ARG_VAL(headers
, 0)
72 HTTP_BEGIN_ARGS(addHeaders
, 0, 1)
73 HTTP_ARG_VAL(headers
, 0)
76 HTTP_EMPTY_ARGS(getCookies
, 0);
77 HTTP_BEGIN_ARGS(setCookies
, 0, 0)
78 HTTP_ARG_VAL(cookies
, 0)
81 HTTP_BEGIN_ARGS(addCookies
, 0, 1)
82 HTTP_ARG_VAL(cookies
, 0)
85 HTTP_EMPTY_ARGS(getUrl
, 0);
86 HTTP_BEGIN_ARGS(setUrl
, 0, 1)
90 HTTP_EMPTY_ARGS(getMethod
, 0);
91 HTTP_BEGIN_ARGS(setMethod
, 0, 1)
92 HTTP_ARG_VAL(request_method
, 0)
95 HTTP_EMPTY_ARGS(getContentType
, 0);
96 HTTP_BEGIN_ARGS(setContentType
, 0, 1)
97 HTTP_ARG_VAL(content_type
, 0)
100 HTTP_EMPTY_ARGS(getQueryData
, 0);
101 HTTP_BEGIN_ARGS(setQueryData
, 0, 0)
102 HTTP_ARG_VAL(query_data
, 0)
105 HTTP_BEGIN_ARGS(addQueryData
, 0, 1)
106 HTTP_ARG_VAL(query_data
, 0)
109 HTTP_EMPTY_ARGS(getPostFields
, 0);
110 HTTP_BEGIN_ARGS(setPostFields
, 0, 0)
111 HTTP_ARG_VAL(post_fields
, 0)
114 HTTP_BEGIN_ARGS(addPostFields
, 0, 1)
115 HTTP_ARG_VAL(post_fields
, 0)
118 HTTP_EMPTY_ARGS(getPostFiles
, 0);
119 HTTP_BEGIN_ARGS(setPostFiles
, 0, 0)
120 HTTP_ARG_VAL(post_files
, 0)
123 HTTP_BEGIN_ARGS(addPostFile
, 0, 2)
124 HTTP_ARG_VAL(formname
, 0)
125 HTTP_ARG_VAL(filename
, 0)
126 HTTP_ARG_VAL(content_type
, 0)
129 HTTP_EMPTY_ARGS(getPutFile
, 0);
130 HTTP_BEGIN_ARGS(setPutFile
, 0, 0)
131 HTTP_ARG_VAL(filename
, 0)
134 HTTP_EMPTY_ARGS(getResponseData
, 0);
135 HTTP_BEGIN_ARGS(getResponseHeader
, 0, 0)
136 HTTP_ARG_VAL(name
, 0)
139 HTTP_BEGIN_ARGS(getResponseCookie
, 0, 0)
140 HTTP_ARG_VAL(name
, 0)
143 HTTP_EMPTY_ARGS(getResponseBody
, 0);
144 HTTP_EMPTY_ARGS(getResponseCode
, 0);
145 HTTP_BEGIN_ARGS(getResponseInfo
, 0, 0)
146 HTTP_ARG_VAL(name
, 0)
149 HTTP_EMPTY_ARGS(getResponseMessage
, 1);
150 HTTP_EMPTY_ARGS(getRequestMessage
, 1);
151 HTTP_EMPTY_ARGS(getHistory
, 1);
152 HTTP_EMPTY_ARGS(send
, 1);
154 HTTP_BEGIN_ARGS(get
, 0, 1)
156 HTTP_ARG_VAL(options
, 0)
157 HTTP_ARG_VAL(info
, 1)
160 HTTP_BEGIN_ARGS(head
, 0, 1)
162 HTTP_ARG_VAL(options
, 0)
163 HTTP_ARG_VAL(info
, 1)
166 HTTP_BEGIN_ARGS(postData
, 0, 2)
168 HTTP_ARG_VAL(data
, 0)
169 HTTP_ARG_VAL(options
, 0)
170 HTTP_ARG_VAL(info
, 1)
173 HTTP_BEGIN_ARGS(postFields
, 0, 2)
175 HTTP_ARG_VAL(data
, 0)
176 HTTP_ARG_VAL(options
, 0)
177 HTTP_ARG_VAL(info
, 1)
180 HTTP_BEGIN_ARGS(putFile
, 0, 2)
182 HTTP_ARG_VAL(file
, 0)
183 HTTP_ARG_VAL(options
, 0)
184 HTTP_ARG_VAL(info
, 1)
187 HTTP_BEGIN_ARGS(putStream
, 0, 2)
189 HTTP_ARG_VAL(stream
, 0)
190 HTTP_ARG_VAL(options
, 0)
191 HTTP_ARG_VAL(info
, 1)
194 HTTP_BEGIN_ARGS(methodRegister
, 0, 1)
195 HTTP_ARG_VAL(method_name
, 0)
198 HTTP_BEGIN_ARGS(methodUnregister
, 0, 1)
199 HTTP_ARG_VAL(method
, 0)
202 HTTP_BEGIN_ARGS(methodName
, 0, 1)
203 HTTP_ARG_VAL(method_id
, 0)
206 HTTP_BEGIN_ARGS(methodExists
, 0, 1)
207 HTTP_ARG_VAL(method
, 0)
210 #define http_request_object_declare_default_properties() _http_request_object_declare_default_properties(TSRMLS_C)
211 static inline void _http_request_object_declare_default_properties(TSRMLS_D
);
213 zend_class_entry
*http_request_object_ce
;
214 zend_function_entry http_request_object_fe
[] = {
215 HTTP_REQUEST_ME(__construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
216 HTTP_REQUEST_ME(__destruct
, ZEND_ACC_PUBLIC
|ZEND_ACC_DTOR
)
218 HTTP_REQUEST_ME(setOptions
, ZEND_ACC_PUBLIC
)
219 HTTP_REQUEST_ME(getOptions
, ZEND_ACC_PUBLIC
)
220 HTTP_REQUEST_ME(setSslOptions
, ZEND_ACC_PUBLIC
)
221 HTTP_REQUEST_ME(getSslOptions
, ZEND_ACC_PUBLIC
)
223 HTTP_REQUEST_ME(addHeaders
, ZEND_ACC_PUBLIC
)
224 HTTP_REQUEST_ME(getHeaders
, ZEND_ACC_PUBLIC
)
225 HTTP_REQUEST_ME(setHeaders
, ZEND_ACC_PUBLIC
)
227 HTTP_REQUEST_ME(addCookies
, ZEND_ACC_PUBLIC
)
228 HTTP_REQUEST_ME(getCookies
, ZEND_ACC_PUBLIC
)
229 HTTP_REQUEST_ME(setCookies
, ZEND_ACC_PUBLIC
)
231 HTTP_REQUEST_ME(setMethod
, ZEND_ACC_PUBLIC
)
232 HTTP_REQUEST_ME(getMethod
, ZEND_ACC_PUBLIC
)
234 HTTP_REQUEST_ME(setUrl
, ZEND_ACC_PUBLIC
)
235 HTTP_REQUEST_ME(getUrl
, ZEND_ACC_PUBLIC
)
237 HTTP_REQUEST_ME(setContentType
, ZEND_ACC_PUBLIC
)
238 HTTP_REQUEST_ME(getContentType
, ZEND_ACC_PUBLIC
)
240 HTTP_REQUEST_ME(setQueryData
, ZEND_ACC_PUBLIC
)
241 HTTP_REQUEST_ME(getQueryData
, ZEND_ACC_PUBLIC
)
242 HTTP_REQUEST_ME(addQueryData
, ZEND_ACC_PUBLIC
)
244 HTTP_REQUEST_ME(setPostFields
, ZEND_ACC_PUBLIC
)
245 HTTP_REQUEST_ME(getPostFields
, ZEND_ACC_PUBLIC
)
246 HTTP_REQUEST_ME(addPostFields
, ZEND_ACC_PUBLIC
)
248 HTTP_REQUEST_ME(setPostFiles
, ZEND_ACC_PUBLIC
)
249 HTTP_REQUEST_ME(addPostFile
, ZEND_ACC_PUBLIC
)
250 HTTP_REQUEST_ME(getPostFiles
, ZEND_ACC_PUBLIC
)
252 HTTP_REQUEST_ME(setPutFile
, ZEND_ACC_PUBLIC
)
253 HTTP_REQUEST_ME(getPutFile
, ZEND_ACC_PUBLIC
)
255 HTTP_REQUEST_ME(send
, ZEND_ACC_PUBLIC
)
257 HTTP_REQUEST_ME(getResponseData
, ZEND_ACC_PUBLIC
)
258 HTTP_REQUEST_ME(getResponseHeader
, ZEND_ACC_PUBLIC
)
259 HTTP_REQUEST_ME(getResponseCookie
, ZEND_ACC_PUBLIC
)
260 HTTP_REQUEST_ME(getResponseCode
, ZEND_ACC_PUBLIC
)
261 HTTP_REQUEST_ME(getResponseBody
, ZEND_ACC_PUBLIC
)
262 HTTP_REQUEST_ME(getResponseInfo
, ZEND_ACC_PUBLIC
)
263 HTTP_REQUEST_ME(getResponseMessage
, ZEND_ACC_PUBLIC
)
264 HTTP_REQUEST_ME(getRequestMessage
, ZEND_ACC_PUBLIC
)
265 HTTP_REQUEST_ME(getHistory
, ZEND_ACC_PUBLIC
)
267 HTTP_REQUEST_ALIAS(get
, http_get
)
268 HTTP_REQUEST_ALIAS(head
, http_head
)
269 HTTP_REQUEST_ALIAS(postData
, http_post_data
)
270 HTTP_REQUEST_ALIAS(postFields
, http_post_fields
)
271 HTTP_REQUEST_ALIAS(putFile
, http_put_file
)
272 HTTP_REQUEST_ALIAS(putStream
, http_put_stream
)
274 HTTP_REQUEST_ALIAS(methodRegister
, http_request_method_register
)
275 HTTP_REQUEST_ALIAS(methodUnregister
, http_request_method_unregister
)
276 HTTP_REQUEST_ALIAS(methodName
, http_request_method_name
)
277 HTTP_REQUEST_ALIAS(methodExists
, http_request_method_exists
)
281 static zend_object_handlers http_request_object_handlers
;
283 void _http_request_object_init(INIT_FUNC_ARGS
)
285 HTTP_REGISTER_CLASS_EX(HttpRequest
, http_request_object
, NULL
, 0);
288 HTTP_LONG_CONSTANT("HTTP_GET", HTTP_GET
);
289 HTTP_LONG_CONSTANT("HTTP_HEAD", HTTP_HEAD
);
290 HTTP_LONG_CONSTANT("HTTP_POST", HTTP_POST
);
291 HTTP_LONG_CONSTANT("HTTP_PUT", HTTP_PUT
);
292 HTTP_LONG_CONSTANT("HTTP_DELETE", HTTP_DELETE
);
293 HTTP_LONG_CONSTANT("HTTP_OPTIONS", HTTP_OPTIONS
);
294 HTTP_LONG_CONSTANT("HTTP_TRACE", HTTP_TRACE
);
295 HTTP_LONG_CONSTANT("HTTP_CONNECT", HTTP_CONNECT
);
296 /* WebDAV - RFC 2518 */
297 HTTP_LONG_CONSTANT("HTTP_PROPFIND", HTTP_PROPFIND
);
298 HTTP_LONG_CONSTANT("HTTP_PROPPATCH", HTTP_PROPPATCH
);
299 HTTP_LONG_CONSTANT("HTTP_MKCOL", HTTP_MKCOL
);
300 HTTP_LONG_CONSTANT("HTTP_COPY", HTTP_COPY
);
301 HTTP_LONG_CONSTANT("HTTP_MOVE", HTTP_MOVE
);
302 HTTP_LONG_CONSTANT("HTTP_LOCK", HTTP_LOCK
);
303 HTTP_LONG_CONSTANT("HTTP_UNLOCK", HTTP_UNLOCK
);
304 /* WebDAV Versioning - RFC 3253 */
305 HTTP_LONG_CONSTANT("HTTP_VERSION_CONTROL", HTTP_VERSION_CONTROL
);
306 HTTP_LONG_CONSTANT("HTTP_REPORT", HTTP_REPORT
);
307 HTTP_LONG_CONSTANT("HTTP_CHECKOUT", HTTP_CHECKOUT
);
308 HTTP_LONG_CONSTANT("HTTP_CHECKIN", HTTP_CHECKIN
);
309 HTTP_LONG_CONSTANT("HTTP_UNCHECKOUT", HTTP_UNCHECKOUT
);
310 HTTP_LONG_CONSTANT("HTTP_MKWORKSPACE", HTTP_MKWORKSPACE
);
311 HTTP_LONG_CONSTANT("HTTP_UPDATE", HTTP_UPDATE
);
312 HTTP_LONG_CONSTANT("HTTP_LABEL", HTTP_LABEL
);
313 HTTP_LONG_CONSTANT("HTTP_MERGE", HTTP_MERGE
);
314 HTTP_LONG_CONSTANT("HTTP_BASELINE_CONTROL", HTTP_BASELINE_CONTROL
);
315 HTTP_LONG_CONSTANT("HTTP_MKACTIVITY", HTTP_MKACTIVITY
);
316 /* WebDAV Access Control - RFC 3744 */
317 HTTP_LONG_CONSTANT("HTTP_ACL", HTTP_ACL
);
320 # if LIBCURL_VERSION_NUM >= 0x070a05
321 HTTP_LONG_CONSTANT("HTTP_AUTH_BASIC", CURLAUTH_BASIC
);
322 HTTP_LONG_CONSTANT("HTTP_AUTH_DIGEST", CURLAUTH_DIGEST
);
323 HTTP_LONG_CONSTANT("HTTP_AUTH_NTLM", CURLAUTH_NTLM
);
324 # endif /* LIBCURL_VERSION_NUM */
327 zend_object_value
_http_request_object_new(zend_class_entry
*ce TSRMLS_DC
)
329 zend_object_value ov
;
330 http_request_object
*o
;
332 o
= ecalloc(1, sizeof(http_request_object
));
334 o
->ch
= curl_easy_init();
337 phpstr_init(&o
->history
);
338 phpstr_init(&o
->request
);
339 phpstr_init_ex(&o
->response
, HTTP_CURLBUF_SIZE
, 0);
341 ALLOC_HASHTABLE(OBJ_PROP(o
));
342 zend_hash_init(OBJ_PROP(o
), 0, NULL
, ZVAL_PTR_DTOR
, 0);
343 zend_hash_copy(OBJ_PROP(o
), &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
345 ov
.handle
= putObject(http_request_object
, o
);
346 ov
.handlers
= &http_request_object_handlers
;
351 static inline void _http_request_object_declare_default_properties(TSRMLS_D
)
353 zend_class_entry
*ce
= http_request_object_ce
;
355 DCL_PROP_N(PROTECTED
, options
);
356 DCL_PROP_N(PROTECTED
, responseInfo
);
357 DCL_PROP_N(PROTECTED
, responseData
);
358 DCL_PROP_N(PROTECTED
, responseCode
);
359 DCL_PROP_N(PROTECTED
, responseMessage
);
360 DCL_PROP_N(PROTECTED
, postFields
);
361 DCL_PROP_N(PROTECTED
, postFiles
);
363 DCL_PROP(PROTECTED
, long, method
, HTTP_GET
);
365 DCL_PROP(PROTECTED
, string
, url
, "");
366 DCL_PROP(PROTECTED
, string
, contentType
, "");
367 DCL_PROP(PROTECTED
, string
, queryData
, "");
368 DCL_PROP(PROTECTED
, string
, putFile
, "");
370 DCL_PROP(PUBLIC
, bool, recordHistory
, 1);
373 void _http_request_object_free(zend_object
*object TSRMLS_DC
)
375 http_request_object
*o
= (http_request_object
*) object
;
378 zend_hash_destroy(OBJ_PROP(o
));
379 FREE_HASHTABLE(OBJ_PROP(o
));
382 /* avoid nasty segfaults with already cleaned up callbacks */
383 curl_easy_setopt(o
->ch
, CURLOPT_NOPROGRESS
, 1);
384 curl_easy_setopt(o
->ch
, CURLOPT_PROGRESSFUNCTION
, NULL
);
385 curl_easy_setopt(o
->ch
, CURLOPT_VERBOSE
, 0);
386 curl_easy_setopt(o
->ch
, CURLOPT_DEBUGFUNCTION
, NULL
);
387 curl_easy_cleanup(o
->ch
);
389 phpstr_dtor(&o
->response
);
390 phpstr_dtor(&o
->request
);
391 phpstr_dtor(&o
->history
);
395 STATUS
_http_request_object_requesthandler(http_request_object
*obj
, zval
*this_ptr
, http_request_body
*body TSRMLS_DC
)
397 zval
*meth
, *URL
, *qdata
, *opts
;
404 if ((!obj
->ch
) && (!(obj
->ch
= curl_easy_init()))) {
405 http_error(HE_WARNING
, HTTP_E_REQUEST
, "Could not initilaize curl");
409 meth
= GET_PROP(obj
, method
);
410 URL
= GET_PROP(obj
, url
);
411 qdata
= GET_PROP(obj
, queryData
);
412 opts
= GET_PROP(obj
, options
);
414 // HTTP_URI_MAXLEN+1 long char *
415 if (!(request_uri
= http_absolute_uri_ex(Z_STRVAL_P(URL
), Z_STRLEN_P(URL
), NULL
, 0, NULL
, 0, 0))) {
419 if (Z_STRLEN_P(qdata
) && (strlen(request_uri
) < HTTP_URI_MAXLEN
)) {
420 if (!strchr(request_uri
, '?')) {
421 strcat(request_uri
, "?");
423 strcat(request_uri
, "&");
425 strncat(request_uri
, Z_STRVAL_P(qdata
), HTTP_URI_MAXLEN
- strlen(request_uri
));
428 switch (Z_LVAL_P(meth
))
433 status
= http_request_init(obj
->ch
, Z_LVAL_P(meth
), request_uri
, NULL
, Z_ARRVAL_P(opts
));
439 php_stream_statbuf ssb
;
440 zval
*file
= GET_PROP(obj
, putFile
);
442 if ( (stream
= php_stream_open_wrapper(Z_STRVAL_P(file
), "rb", REPORT_ERRORS
|ENFORCE_SAFE_MODE
, NULL
)) &&
443 !php_stream_stat(stream
, &ssb
)) {
444 body
->type
= HTTP_REQUEST_BODY_UPLOADFILE
;
446 body
->size
= ssb
.sb
.st_size
;
448 status
= http_request_init(obj
->ch
, HTTP_PUT
, request_uri
, body
, Z_ARRVAL_P(opts
));
457 zval
*fields
= GET_PROP(obj
, postFields
), *files
= GET_PROP(obj
, postFiles
);
459 if (SUCCESS
== (status
= http_request_body_fill(body
, Z_ARRVAL_P(fields
), Z_ARRVAL_P(files
)))) {
460 status
= http_request_init(obj
->ch
, HTTP_POST
, request_uri
, body
, Z_ARRVAL_P(opts
));
467 zval
*post
= GET_PROP(obj
, postData
);
469 body
->type
= HTTP_REQUEST_BODY_CSTRING
;
470 body
->data
= Z_STRVAL_P(post
);
471 body
->size
= Z_STRLEN_P(post
);
473 status
= http_request_init(obj
->ch
, Z_LVAL_P(meth
), request_uri
, body
, Z_ARRVAL_P(opts
));
478 /* clean previous response */
479 phpstr_dtor(&obj
->response
);
480 /* clean previous request */
481 phpstr_dtor(&obj
->request
);
487 STATUS
_http_request_object_responsehandler(http_request_object
*obj
, zval
*this_ptr TSRMLS_DC
)
491 phpstr_fix(&obj
->request
);
492 phpstr_fix(&obj
->response
);
494 if (msg
= http_message_parse(PHPSTR_VAL(&obj
->response
), PHPSTR_LEN(&obj
->response
))) {
497 zval
*headers
, *message
,
498 *resp
= GET_PROP(obj
, responseData
),
499 *info
= GET_PROP(obj
, responseInfo
),
500 *hist
= GET_PROP(obj
, recordHistory
);
502 /* should we record history? */
503 if (Z_TYPE_P(hist
) != IS_BOOL
) {
504 convert_to_boolean_ex(&hist
);
506 if (Z_LVAL_P(hist
)) {
507 /* we need to act like a zipper, as we'll receive
508 * the requests and the responses in separate chains
511 http_message
*response
= msg
, *request
= http_message_parse(PHPSTR_VAL(&obj
->request
), PHPSTR_LEN(&obj
->request
));
512 http_message
*free_msg
= request
;
518 http_message_tostring(response
, &message
, &msglen
);
519 phpstr_append(&obj
->history
, message
, msglen
);
522 http_message_tostring(request
, &message
, &msglen
);
523 phpstr_append(&obj
->history
, message
, msglen
);
526 } while ((response
= response
->parent
) && (request
= request
->parent
));
528 http_message_free(&free_msg
);
529 phpstr_fix(&obj
->history
);
532 UPD_PROP(obj
, long, responseCode
, msg
->http
.info
.response
.code
);
534 MAKE_STD_ZVAL(headers
)
537 zend_hash_copy(Z_ARRVAL_P(headers
), &msg
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
538 phpstr_data(PHPSTR(msg
), &body
, &body_len
);
540 add_assoc_zval(resp
, "headers", headers
);
541 add_assoc_stringl(resp
, "body", body
, body_len
, 0);
543 MAKE_STD_ZVAL(message
);
544 message
->type
= IS_OBJECT
;
546 message
->value
.obj
= http_message_object_from_msg(msg
);
547 SET_PROP(obj
, responseMessage
, message
);
548 zval_ptr_dtor(&message
);
550 http_request_info(obj
->ch
, Z_ARRVAL_P(info
));
551 SET_PROP(obj
, responseInfo
, info
);
558 #define http_request_object_set_options_subr(key, ow) \
559 _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow))
560 static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS
, char *key
, size_t len
, int overwrite
)
562 zval
*opts
, **options
, *new_options
= NULL
;
563 getObject(http_request_object
, obj
);
565 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a/!", &new_options
)) {
569 opts
= GET_PROP(obj
, options
);
571 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(opts
), key
, len
, (void **) &options
)) {
573 zend_hash_clean(Z_ARRVAL_PP(options
));
575 if (new_options
&& zend_hash_num_elements(Z_ARRVAL_P(new_options
))) {
577 array_copy(new_options
, *options
);
579 array_merge(new_options
, *options
);
582 } else if (new_options
&& zend_hash_num_elements(Z_ARRVAL_P(new_options
))) {
583 zval_add_ref(&new_options
);
584 add_assoc_zval(opts
, key
, new_options
);
590 #define http_request_object_get_options_subr(key) \
591 _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
592 static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS
, char *key
, size_t len
)
597 zval
*opts
, **options
;
598 getObject(http_request_object
, obj
);
600 opts
= GET_PROP(obj
, options
);
602 array_init(return_value
);
604 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(opts
), key
, len
, (void **) &options
)) {
605 array_copy(*options
, return_value
);
611 /* ### USERLAND ### */
613 /* {{{ proto void HttpRequest::__construct([string url[, long request_method = HTTP_GET]])
615 * Instantiate a new HttpRequest object which can be used to issue HEAD, GET
616 * and POST (including posting files) HTTP requests.
618 PHP_METHOD(HttpRequest
, __construct
)
623 getObject(http_request_object
, obj
);
626 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sl", &URL
, &URL_len
, &meth
)) {
627 INIT_PARR(obj
, options
);
628 INIT_PARR(obj
, responseInfo
);
629 INIT_PARR(obj
, responseData
);
630 INIT_PARR(obj
, postFields
);
631 INIT_PARR(obj
, postFiles
);
634 UPD_PROP(obj
, string
, url
, URL
);
637 UPD_PROP(obj
, long, method
, meth
);
644 /* {{{ proto void HttpRequest::__destruct()
646 * Destroys the HttpRequest object.
648 PHP_METHOD(HttpRequest
, __destruct
)
650 getObject(http_request_object
, obj
);
654 FREE_PARR(obj
, options
);
655 FREE_PARR(obj
, responseInfo
);
656 FREE_PARR(obj
, responseData
);
657 FREE_PARR(obj
, postFields
);
658 FREE_PARR(obj
, postFiles
);
662 /* {{{ proto bool HttpRequest::setOptions([array options])
664 * Set the request options to use. See http_get() for a full list of available options.
666 PHP_METHOD(HttpRequest
, setOptions
)
670 zval
*opts
= NULL
, *old_opts
, **opt
;
671 getObject(http_request_object
, obj
);
673 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a/!", &opts
)) {
677 old_opts
= GET_PROP(obj
, options
);
679 if (!opts
|| !zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
680 zend_hash_clean(Z_ARRVAL_P(old_opts
));
684 /* some options need extra attention -- thus cannot use array_merge() directly */
685 FOREACH_KEYVAL(opts
, key
, idx
, opt
) {
687 if (!strcmp(key
, "headers")) {
689 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(old_opts
), "headers", sizeof("headers"), (void **) &headers
)) {
690 array_merge(*opt
, *headers
);
693 } else if (!strcmp(key
, "cookies")) {
695 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(old_opts
), "cookies", sizeof("cookies"), (void **) &cookies
)) {
696 array_merge(*opt
, *cookies
);
699 } else if (!strcmp(key
, "ssl")) {
701 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(old_opts
), "ssl", sizeof("ssl"), (void **) &ssl
)) {
702 array_merge(*opt
, *ssl
);
705 }else if ((!strcasecmp(key
, "url")) || (!strcasecmp(key
, "uri"))) {
706 if (Z_TYPE_PP(opt
) != IS_STRING
) {
707 convert_to_string_ex(opt
);
709 UPD_PROP(obj
, string
, url
, Z_STRVAL_PP(opt
));
711 } else if (!strcmp(key
, "method")) {
712 if (Z_TYPE_PP(opt
) != IS_LONG
) {
713 convert_to_long_ex(opt
);
715 UPD_PROP(obj
, long, method
, Z_LVAL_PP(opt
));
720 add_assoc_zval(old_opts
, key
, *opt
);
731 /* {{{ proto array HttpRequest::getOptions()
733 * Get currently set options.
735 PHP_METHOD(HttpRequest
, getOptions
)
741 getObject(http_request_object
, obj
);
743 opts
= GET_PROP(obj
, options
);
744 array_init(return_value
);
745 array_copy(opts
, return_value
);
750 /* {{{ proto bool HttpRequest::setSslOptions([array options])
754 PHP_METHOD(HttpRequest
, setSslOptions
)
756 http_request_object_set_options_subr("ssl", 1);
760 /* {{{ proto bool HttpRequest::addSslOptions(array options)
762 * Set additional SSL options.
764 PHP_METHOD(HttpRequest
, addSslOptions
)
766 http_request_object_set_options_subr("ssl", 0);
770 /* {{{ proto array HttpRequest::getSslOtpions()
772 * Get previously set SSL options.
774 PHP_METHOD(HttpRequest
, getSslOptions
)
776 http_request_object_get_options_subr("ssl");
780 /* {{{ proto bool HttpRequest::addHeaders(array headers)
782 * Add request header name/value pairs.
784 PHP_METHOD(HttpRequest
, addHeaders
)
786 http_request_object_set_options_subr("headers", 0);
789 /* {{{ proto bool HttpRequest::setHeaders([array headers])
791 * Set request header name/value pairs.
793 PHP_METHOD(HttpRequest
, setHeaders
)
795 http_request_object_set_options_subr("headers", 1);
799 /* {{{ proto array HttpRequest::getHeaders()
801 * Get previously set request headers.
803 PHP_METHOD(HttpRequest
, getHeaders
)
805 http_request_object_get_options_subr("headers");
809 /* {{{ proto bool HttpRequest::setCookies([array cookies])
813 PHP_METHOD(HttpRequest
, setCookies
)
815 http_request_object_set_options_subr("cookies", 1);
819 /* {{{ proto bool HttpRequest::addCookies(array cookies)
823 PHP_METHOD(HttpRequest
, addCookies
)
825 http_request_object_set_options_subr("cookies", 0);
829 /* {{{ proto array HttpRequest::getCookies()
831 * Get previously set cookies.
833 PHP_METHOD(HttpRequest
, getCookies
)
835 http_request_object_get_options_subr("cookies");
839 /* {{{ proto bool HttpRequest::setUrl(string url)
841 * Set the request URL.
843 PHP_METHOD(HttpRequest
, setUrl
)
847 getObject(http_request_object
, obj
);
849 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &URL
, &URL_len
)) {
853 UPD_PROP(obj
, string
, url
, URL
);
858 /* {{{ proto string HttpRequest::getUrl()
860 * Get the previously set request URL.
862 PHP_METHOD(HttpRequest
, getUrl
)
868 getObject(http_request_object
, obj
);
870 URL
= GET_PROP(obj
, url
);
871 RETURN_STRINGL(Z_STRVAL_P(URL
), Z_STRLEN_P(URL
), 1);
876 /* {{{ proto bool HttpRequest::setMethod(long request_method)
878 * Set the request methods; one of the <tt>HTTP_HEAD</tt>, <tt>HTTP_GET</tt> or
879 * <tt>HTTP_POST</tt> constants.
881 PHP_METHOD(HttpRequest
, setMethod
)
884 getObject(http_request_object
, obj
);
886 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &meth
)) {
890 UPD_PROP(obj
, long, method
, meth
);
895 /* {{{ proto long HttpRequest::getMethod()
897 * Get the previously set request method.
899 PHP_METHOD(HttpRequest
, getMethod
)
905 getObject(http_request_object
, obj
);
907 meth
= GET_PROP(obj
, method
);
908 RETURN_LONG(Z_LVAL_P(meth
));
913 /* {{{ proto bool HttpRequest::setContentType(string content_type)
915 * Set the content type the post request should have.
916 * Use this only if you know what you're doing.
918 PHP_METHOD(HttpRequest
, setContentType
)
922 getObject(http_request_object
, obj
);
924 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &ctype
, &ct_len
)) {
928 if (!strchr(ctype
, '/')) {
929 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", ctype
);
933 UPD_PROP(obj
, string
, contentType
, ctype
);
938 /* {{{ proto string HttpRequest::getContentType()
940 * Get the previously content type.
942 PHP_METHOD(HttpRequest
, getContentType
)
948 getObject(http_request_object
, obj
);
950 ctype
= GET_PROP(obj
, contentType
);
951 RETURN_STRINGL(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
956 /* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
958 * Set the URL query parameters to use.
959 * Overwrites previously set query parameters.
960 * Affects any request types.
962 PHP_METHOD(HttpRequest
, setQueryData
)
965 getObject(http_request_object
, obj
);
967 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z!", &qdata
)) {
971 if ((!qdata
) || Z_TYPE_P(qdata
) == IS_NULL
) {
972 UPD_PROP(obj
, string
, queryData
, "");
973 } else if ((Z_TYPE_P(qdata
) == IS_ARRAY
) || (Z_TYPE_P(qdata
) == IS_OBJECT
)) {
974 char *query_data
= NULL
;
976 if (SUCCESS
!= http_urlencode_hash(HASH_OF(qdata
), &query_data
)) {
980 UPD_PROP(obj
, string
, queryData
, query_data
);
983 convert_to_string(qdata
);
984 UPD_PROP(obj
, string
, queryData
, Z_STRVAL_P(qdata
));
990 /* {{{ proto string HttpRequest::getQueryData()
992 * Get the current query data in form of an urlencoded query string.
994 PHP_METHOD(HttpRequest
, getQueryData
)
1000 getObject(http_request_object
, obj
);
1002 qdata
= GET_PROP(obj
, queryData
);
1003 RETURN_STRINGL(Z_STRVAL_P(qdata
), Z_STRLEN_P(qdata
), 1);
1008 /* {{{ proto bool HttpRequest::addQueryData(array query_params)
1010 * Add parameters to the query parameter list.
1011 * Affects any request type.
1013 PHP_METHOD(HttpRequest
, addQueryData
)
1015 zval
*qdata
, *old_qdata
;
1016 char *query_data
= NULL
;
1017 getObject(http_request_object
, obj
);
1019 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a", &qdata
)) {
1023 old_qdata
= GET_PROP(obj
, queryData
);
1025 if (SUCCESS
!= http_urlencode_hash_ex(HASH_OF(qdata
), 1, Z_STRVAL_P(old_qdata
), Z_STRLEN_P(old_qdata
), &query_data
, NULL
)) {
1029 UPD_PROP(obj
, string
, queryData
, query_data
);
1036 /* {{{ proto bool HttpRequest::addPostFields(array post_data)
1038 * Adds POST data entries.
1039 * Affects only POST requests.
1041 PHP_METHOD(HttpRequest
, addPostFields
)
1043 zval
*post
, *post_data
;
1044 getObject(http_request_object
, obj
);
1046 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a", &post_data
)) {
1050 post
= GET_PROP(obj
, postFields
);
1051 array_merge(post_data
, post
);
1057 /* {{{ proto bool HttpRequest::setPostFields([array post_data])
1059 * Set the POST data entries.
1060 * Overwrites previously set POST data.
1061 * Affects only POST requests.
1063 PHP_METHOD(HttpRequest
, setPostFields
)
1065 zval
*post
, *post_data
= NULL
;
1066 getObject(http_request_object
, obj
);
1068 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a!", &post_data
)) {
1072 post
= GET_PROP(obj
, postFields
);
1073 zend_hash_clean(Z_ARRVAL_P(post
));
1075 if (post_data
&& zend_hash_num_elements(Z_ARRVAL_P(post_data
))) {
1076 array_copy(post_data
, post
);
1083 /* {{{ proto array HttpRequest::getPostFields()
1085 * Get previously set POST data.
1087 PHP_METHOD(HttpRequest
, getPostFields
)
1093 getObject(http_request_object
, obj
);
1095 post_data
= GET_PROP(obj
, postFields
);
1096 array_init(return_value
);
1097 array_copy(post_data
, return_value
);
1102 /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
1104 * Add a file to the POST request.
1105 * Affects only POST requests.
1107 PHP_METHOD(HttpRequest
, addPostFile
)
1109 zval
*files
, *entry
;
1110 char *name
, *file
, *type
= NULL
;
1111 int name_len
, file_len
, type_len
= 0;
1112 getObject(http_request_object
, obj
);
1114 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|s", &name
, &name_len
, &file
, &file_len
, &type
, &type_len
)) {
1119 if (!strchr(type
, '/')) {
1120 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Content-Type '%s' doesn't seem to contain a primary and a secondary part", type
);
1124 type
= "application/x-octetstream";
1125 type_len
= sizeof("application/x-octetstream") - 1;
1128 MAKE_STD_ZVAL(entry
);
1131 add_assoc_stringl(entry
, "name", name
, name_len
, 1);
1132 add_assoc_stringl(entry
, "type", type
, type_len
, 1);
1133 add_assoc_stringl(entry
, "file", file
, file_len
, 1);
1135 files
= GET_PROP(obj
, postFiles
);
1136 add_next_index_zval(files
, entry
);
1142 /* {{{ proto bool HttpRequest::setPostFiles([array post_files])
1144 * Set files to post.
1145 * Overwrites previously set post files.
1146 * Affects only POST requests.
1148 PHP_METHOD(HttpRequest
, setPostFiles
)
1150 zval
*files
, *pFiles
;
1151 getObject(http_request_object
, obj
);
1153 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a", &files
)) {
1157 pFiles
= GET_PROP(obj
, postFiles
);
1158 zend_hash_clean(Z_ARRVAL_P(pFiles
));
1160 if (files
&& zend_hash_num_elements(Z_ARRVAL_P(files
))) {
1161 array_copy(files
, pFiles
);
1168 /* {{{ proto array HttpRequest::getPostFiles()
1170 * Get all previously added POST files.
1172 PHP_METHOD(HttpRequest
, getPostFiles
)
1178 getObject(http_request_object
, obj
);
1180 files
= GET_PROP(obj
, postFiles
);
1182 array_init(return_value
);
1183 array_copy(files
, return_value
);
1188 /* {{{ proto bool HttpRequest::setPutFile([string file])
1191 * Affects only PUT requests.
1193 PHP_METHOD(HttpRequest
, setPutFile
)
1197 getObject(http_request_object
, obj
);
1199 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &file
, &file_len
)) {
1203 UPD_PROP(obj
, string
, putFile
, file
);
1208 /* {{{ proto string HttpRequest::getPutFile()
1210 * Get previously set put file.
1212 PHP_METHOD(HttpRequest
, getPutFile
)
1218 getObject(http_request_object
, obj
);
1220 putfile
= GET_PROP(obj
, putFile
);
1221 RETVAL_STRINGL(Z_STRVAL_P(putfile
), Z_STRLEN_P(putfile
), 1);
1226 /* {{{ proto array HttpRequest::getResponseData()
1228 * Get all response data after the request has been sent.
1230 PHP_METHOD(HttpRequest
, getResponseData
)
1236 getObject(http_request_object
, obj
);
1238 data
= GET_PROP(obj
, responseData
);
1239 array_init(return_value
);
1240 array_copy(data
, return_value
);
1245 /* {{{ proto mixed HttpRequest::getResponseHeader([string name])
1247 * Get response header(s) after the request has been sent.
1249 PHP_METHOD(HttpRequest
, getResponseHeader
)
1252 zval
*data
, **headers
, **header
;
1253 char *header_name
= NULL
;
1255 getObject(http_request_object
, obj
);
1257 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &header_name
, &header_len
)) {
1261 data
= GET_PROP(obj
, responseData
);
1262 if (SUCCESS
!= zend_hash_find(Z_ARRVAL_P(data
), "headers", sizeof("headers"), (void **) &headers
)) {
1266 if (!header_len
|| !header_name
) {
1267 array_init(return_value
);
1268 array_copy(*headers
, return_value
);
1269 } else if (SUCCESS
== zend_hash_find(Z_ARRVAL_PP(headers
), pretty_key(header_name
, header_len
, 1, 1), header_len
+ 1, (void **) &header
)) {
1270 RETURN_STRINGL(Z_STRVAL_PP(header
), Z_STRLEN_PP(header
), 1);
1278 /* {{{ proto array HttpRequest::getResponseCookie([string name])
1280 * Get response cookie(s) after the request has been sent.
1282 PHP_METHOD(HttpRequest
, getResponseCookie
)
1285 zval
*data
, **headers
;
1286 char *cookie_name
= NULL
;
1288 getObject(http_request_object
, obj
);
1290 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &cookie_name
, &cookie_len
)) {
1294 array_init(return_value
);
1296 data
= GET_PROP(obj
, responseData
);
1297 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(data
), "headers", sizeof("headers"), (void **) &headers
)) {
1300 zval
**header
= NULL
;
1302 FOREACH_HASH_KEYVAL(Z_ARRVAL_PP(headers
), key
, idx
, header
) {
1303 if (key
&& !strcasecmp(key
, "Set-Cookie")) {
1304 /* several cookies? */
1305 if (Z_TYPE_PP(header
) == IS_ARRAY
) {
1308 FOREACH_HASH_VAL(Z_ARRVAL_PP(header
), cookie
) {
1310 MAKE_STD_ZVAL(cookie_hash
);
1311 array_init(cookie_hash
);
1313 if (SUCCESS
== http_parse_cookie(Z_STRVAL_PP(cookie
), Z_ARRVAL_P(cookie_hash
))) {
1315 add_next_index_zval(return_value
, cookie_hash
);
1319 if ( (SUCCESS
== zend_hash_find(Z_ARRVAL_P(cookie_hash
), "name", sizeof("name"), (void **) &name
)) &&
1320 (!strcmp(Z_STRVAL_PP(name
), cookie_name
))) {
1321 add_next_index_zval(return_value
, cookie_hash
);
1322 return; /* <<< FOUND >>> */
1324 zval_dtor(cookie_hash
);
1329 zval_dtor(cookie_hash
);
1335 MAKE_STD_ZVAL(cookie_hash
);
1336 array_init(cookie_hash
);
1338 if (SUCCESS
== http_parse_cookie(Z_STRVAL_PP(header
), Z_ARRVAL_P(cookie_hash
))) {
1340 add_next_index_zval(return_value
, cookie_hash
);
1344 if ( (SUCCESS
== zend_hash_find(Z_ARRVAL_P(cookie_hash
), "name", sizeof("name"), (void **) &name
)) &&
1345 (!strcmp(Z_STRVAL_PP(name
), cookie_name
))) {
1346 add_next_index_zval(return_value
, cookie_hash
);
1348 zval_dtor(cookie_hash
);
1353 zval_dtor(cookie_hash
);
1367 /* {{{ proto string HttpRequest::getResponseBody()
1369 * Get the response body after the request has been sent.
1371 PHP_METHOD(HttpRequest
, getResponseBody
)
1377 getObject(http_request_object
, obj
);
1379 data
= GET_PROP(obj
, responseData
);
1380 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(data
), "body", sizeof("body"), (void **) &body
)) {
1381 RETURN_STRINGL(Z_STRVAL_PP(body
), Z_STRLEN_PP(body
), 1);
1389 /* {{{ proto int HttpRequest::getResponseCode()
1391 * Get the response code after the request has been sent.
1393 PHP_METHOD(HttpRequest
, getResponseCode
)
1399 getObject(http_request_object
, obj
);
1401 code
= GET_PROP(obj
, responseCode
);
1402 RETURN_LONG(Z_LVAL_P(code
));
1407 /* {{{ proto array HttpRequest::getResponseInfo([string name])
1409 * Get response info after the request has been sent.
1410 * See http_get() for a full list of returned info.
1412 PHP_METHOD(HttpRequest
, getResponseInfo
)
1415 zval
*info
, **infop
;
1416 char *info_name
= NULL
;
1418 getObject(http_request_object
, obj
);
1420 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &info_name
, &info_len
)) {
1424 info
= GET_PROP(obj
, responseInfo
);
1426 if (info_len
&& info_name
) {
1427 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(info
), pretty_key(info_name
, info_len
, 0, 0), info_len
+ 1, (void **) &infop
)) {
1428 RETURN_ZVAL(*infop
, 1, ZVAL_PTR_DTOR
);
1430 http_error_ex(HE_NOTICE
, HTTP_E_INVALID_PARAM
, "Could not find response info named %s", info_name
);
1434 array_init(return_value
);
1435 array_copy(info
, return_value
);
1441 /* {{{ proto HttpMessage HttpRequest::getResponseMessage()
1443 * Get the full response as HttpMessage object.
1445 PHP_METHOD(HttpRequest
, getResponseMessage
)
1451 getObject(http_request_object
, obj
);
1453 SET_EH_THROW_HTTP();
1454 message
= GET_PROP(obj
, responseMessage
);
1455 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1456 RETVAL_OBJECT(message
);
1465 /* {{{ proto HttpMessage HttpRequest::getRequestMessage()
1467 * Get sent HTTP message.
1469 PHP_METHOD(HttpRequest
, getRequestMessage
)
1475 getObject(http_request_object
, obj
);
1477 SET_EH_THROW_HTTP();
1478 if (msg
= http_message_parse(PHPSTR_VAL(&obj
->request
), PHPSTR_LEN(&obj
->request
))) {
1479 RETVAL_OBJVAL(http_message_object_from_msg(msg
));
1486 PHP_METHOD(HttpRequest
, getHistory
)
1492 getObject(http_request_object
, obj
);
1494 SET_EH_THROW_HTTP();
1495 if (msg
= http_message_parse(PHPSTR_VAL(&obj
->history
), PHPSTR_LEN(&obj
->history
))) {
1496 RETVAL_OBJVAL(http_message_object_from_msg(msg
));
1502 /* {{{ proto HttpMessage HttpRequest::send()
1504 * Send the HTTP request.
1509 * $r = new HttpRequest('http://example.com/feed.rss', HTTP_GET);
1510 * $r->setOptions(array('lastmodified' => filemtime('local.rss')));
1511 * $r->addQueryData(array('category' => 3));
1514 * if ($r->getResponseCode() == 200) {
1515 * file_put_contents('local.rss', $r->getResponseBody());
1517 * } catch (HttpException $ex) {
1526 * $r = new HttpRequest('http://example.com/form.php', HTTP_POST);
1527 * $r->setOptions(array('cookies' => array('lang' => 'de')));
1528 * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
1529 * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
1531 * echo $r->send()->getBody();
1532 * } catch (HttpException $ex) {
1538 PHP_METHOD(HttpRequest
, send
)
1540 STATUS status
= FAILURE
;
1541 http_request_body body
= {0, NULL
, 0};
1542 getObject(http_request_object
, obj
);
1546 SET_EH_THROW_HTTP();
1549 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool");
1554 if (SUCCESS
== (status
= http_request_object_requesthandler(obj
, getThis(), &body
))) {
1555 status
= http_request_exec(obj
->ch
, NULL
, &obj
->response
, &obj
->request
);
1557 http_request_body_dtor(&body
);
1559 /* final data handling */
1560 if (SUCCESS
== status
) {
1561 status
= http_request_object_responsehandler(obj
, getThis());
1564 RETVAL_OBJECT(GET_PROP(obj
, responseMessage
));
1569 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
1576 * vim600: noet sw=4 ts=4 fdm=marker
1577 * vim<600: noet sw=4 ts=4