2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2006, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
15 #define HTTP_WANT_CURL
18 #if defined(ZEND_ENGINE_2) && defined(HTTP_HAVE_CURL)
20 #include "zend_interfaces.h"
22 #include "php_http_api.h"
23 #include "php_http_cookie_api.h"
24 #include "php_http_exception_object.h"
25 #include "php_http_message_api.h"
26 #include "php_http_message_object.h"
27 #include "php_http_request_api.h"
28 #include "php_http_request_object.h"
29 #include "php_http_request_pool_api.h"
30 #include "php_http_url_api.h"
32 #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpRequest, method, 0, req_args)
33 #define HTTP_EMPTY_ARGS(method) HTTP_EMPTY_ARGS_EX(HttpRequest, method, 0)
34 #define HTTP_REQUEST_ME(method, visibility) PHP_ME(HttpRequest, method, HTTP_ARGS(HttpRequest, method), visibility)
35 #define HTTP_REQUEST_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpRequest, method))
37 HTTP_BEGIN_ARGS(__construct
, 0)
39 HTTP_ARG_VAL(method
, 0)
40 HTTP_ARG_VAL(options
, 0)
43 HTTP_EMPTY_ARGS(getOptions
);
44 HTTP_BEGIN_ARGS(setOptions
, 0)
45 HTTP_ARG_VAL(options
, 0)
48 HTTP_EMPTY_ARGS(getSslOptions
);
49 HTTP_BEGIN_ARGS(setSslOptions
, 0)
50 HTTP_ARG_VAL(ssl_options
, 0)
53 HTTP_BEGIN_ARGS(addSslOptions
, 0)
54 HTTP_ARG_VAL(ssl_optins
, 0)
57 HTTP_EMPTY_ARGS(getHeaders
);
58 HTTP_BEGIN_ARGS(setHeaders
, 0)
59 HTTP_ARG_VAL(headers
, 0)
62 HTTP_BEGIN_ARGS(addHeaders
, 1)
63 HTTP_ARG_VAL(headers
, 0)
66 HTTP_EMPTY_ARGS(getCookies
);
67 HTTP_BEGIN_ARGS(setCookies
, 0)
68 HTTP_ARG_VAL(cookies
, 0)
71 HTTP_BEGIN_ARGS(addCookies
, 1)
72 HTTP_ARG_VAL(cookies
, 0)
75 HTTP_EMPTY_ARGS(enableCookies
);
76 #if HTTP_CURL_VERSION(7,14,1)
77 HTTP_BEGIN_ARGS(resetCookies
, 0)
78 HTTP_ARG_VAL(session_only
, 0)
82 HTTP_EMPTY_ARGS(getUrl
);
83 HTTP_BEGIN_ARGS(setUrl
, 1)
87 HTTP_EMPTY_ARGS(getMethod
);
88 HTTP_BEGIN_ARGS(setMethod
, 1)
89 HTTP_ARG_VAL(request_method
, 0)
92 HTTP_EMPTY_ARGS(getContentType
);
93 HTTP_BEGIN_ARGS(setContentType
, 1)
94 HTTP_ARG_VAL(content_type
, 0)
97 HTTP_EMPTY_ARGS(getQueryData
);
98 HTTP_BEGIN_ARGS(setQueryData
, 0)
99 HTTP_ARG_VAL(query_data
, 0)
102 HTTP_BEGIN_ARGS(addQueryData
, 1)
103 HTTP_ARG_VAL(query_data
, 0)
106 HTTP_EMPTY_ARGS(getPostFields
);
107 HTTP_BEGIN_ARGS(setPostFields
, 0)
108 HTTP_ARG_VAL(post_fields
, 0)
111 HTTP_BEGIN_ARGS(addPostFields
, 1)
112 HTTP_ARG_VAL(post_fields
, 0)
115 HTTP_EMPTY_ARGS(getPostFiles
);
116 HTTP_BEGIN_ARGS(setPostFiles
, 0)
117 HTTP_ARG_VAL(post_files
, 0)
120 HTTP_BEGIN_ARGS(addPostFile
, 2)
121 HTTP_ARG_VAL(formname
, 0)
122 HTTP_ARG_VAL(filename
, 0)
123 HTTP_ARG_VAL(content_type
, 0)
126 HTTP_EMPTY_ARGS(getRawPostData
);
127 HTTP_BEGIN_ARGS(setRawPostData
, 0)
128 HTTP_ARG_VAL(raw_post_data
, 0)
131 HTTP_BEGIN_ARGS(addRawPostData
, 1)
132 HTTP_ARG_VAL(raw_post_data
, 0)
135 HTTP_EMPTY_ARGS(getPutFile
);
136 HTTP_BEGIN_ARGS(setPutFile
, 0)
137 HTTP_ARG_VAL(filename
, 0)
140 HTTP_EMPTY_ARGS(getPutData
);
141 HTTP_BEGIN_ARGS(setPutData
, 0)
142 HTTP_ARG_VAL(put_data
, 0)
145 HTTP_BEGIN_ARGS(addPutData
, 1)
146 HTTP_ARG_VAL(put_data
, 0)
149 HTTP_EMPTY_ARGS(getResponseData
);
150 HTTP_BEGIN_ARGS(getResponseHeader
, 0)
151 HTTP_ARG_VAL(name
, 0)
154 HTTP_BEGIN_ARGS(getResponseCookies
, 0)
155 HTTP_ARG_VAL(flags
, 0)
156 HTTP_ARG_VAL(allowed_extras
, 0)
159 HTTP_EMPTY_ARGS(getResponseBody
);
160 HTTP_EMPTY_ARGS(getResponseCode
);
161 HTTP_EMPTY_ARGS(getResponseStatus
);
162 HTTP_BEGIN_ARGS(getResponseInfo
, 0)
163 HTTP_ARG_VAL(name
, 0)
166 HTTP_EMPTY_ARGS(getResponseMessage
);
167 HTTP_EMPTY_ARGS(getRawResponseMessage
);
168 HTTP_EMPTY_ARGS(getRequestMessage
);
169 HTTP_EMPTY_ARGS(getRawRequestMessage
);
170 HTTP_EMPTY_ARGS(getHistory
);
171 HTTP_EMPTY_ARGS(clearHistory
);
172 HTTP_EMPTY_ARGS(send
);
174 HTTP_BEGIN_ARGS(get
, 1)
176 HTTP_ARG_VAL(options
, 0)
177 HTTP_ARG_VAL(info
, 1)
180 HTTP_BEGIN_ARGS(head
, 1)
182 HTTP_ARG_VAL(options
, 0)
183 HTTP_ARG_VAL(info
, 1)
186 HTTP_BEGIN_ARGS(postData
, 2)
188 HTTP_ARG_VAL(data
, 0)
189 HTTP_ARG_VAL(options
, 0)
190 HTTP_ARG_VAL(info
, 1)
193 HTTP_BEGIN_ARGS(postFields
, 2)
195 HTTP_ARG_VAL(data
, 0)
196 HTTP_ARG_VAL(options
, 0)
197 HTTP_ARG_VAL(info
, 1)
200 HTTP_BEGIN_ARGS(putData
, 2)
202 HTTP_ARG_VAL(data
, 0)
203 HTTP_ARG_VAL(options
, 0)
204 HTTP_ARG_VAL(info
, 1)
207 HTTP_BEGIN_ARGS(putFile
, 2)
209 HTTP_ARG_VAL(file
, 0)
210 HTTP_ARG_VAL(options
, 0)
211 HTTP_ARG_VAL(info
, 1)
214 HTTP_BEGIN_ARGS(putStream
, 2)
216 HTTP_ARG_VAL(stream
, 0)
217 HTTP_ARG_VAL(options
, 0)
218 HTTP_ARG_VAL(info
, 1)
221 HTTP_BEGIN_ARGS(methodRegister
, 1)
222 HTTP_ARG_VAL(method_name
, 0)
225 HTTP_BEGIN_ARGS(methodUnregister
, 1)
226 HTTP_ARG_VAL(method
, 0)
229 HTTP_BEGIN_ARGS(methodName
, 1)
230 HTTP_ARG_VAL(method_id
, 0)
233 HTTP_BEGIN_ARGS(methodExists
, 1)
234 HTTP_ARG_VAL(method
, 0)
237 #ifdef HAVE_CURL_GETFORMDATA
238 HTTP_BEGIN_ARGS(encodeBody
, 2)
239 HTTP_ARG_VAL(fields
, 0)
240 HTTP_ARG_VAL(files
, 0)
244 #define OBJ_PROP_CE http_request_object_ce
245 zend_class_entry
*http_request_object_ce
;
246 zend_function_entry http_request_object_fe
[] = {
247 HTTP_REQUEST_ME(__construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
249 HTTP_REQUEST_ME(setOptions
, ZEND_ACC_PUBLIC
)
250 HTTP_REQUEST_ME(getOptions
, ZEND_ACC_PUBLIC
)
251 HTTP_REQUEST_ME(setSslOptions
, ZEND_ACC_PUBLIC
)
252 HTTP_REQUEST_ME(getSslOptions
, ZEND_ACC_PUBLIC
)
253 HTTP_REQUEST_ME(addSslOptions
, ZEND_ACC_PUBLIC
)
255 HTTP_REQUEST_ME(addHeaders
, ZEND_ACC_PUBLIC
)
256 HTTP_REQUEST_ME(getHeaders
, ZEND_ACC_PUBLIC
)
257 HTTP_REQUEST_ME(setHeaders
, ZEND_ACC_PUBLIC
)
259 HTTP_REQUEST_ME(addCookies
, ZEND_ACC_PUBLIC
)
260 HTTP_REQUEST_ME(getCookies
, ZEND_ACC_PUBLIC
)
261 HTTP_REQUEST_ME(setCookies
, ZEND_ACC_PUBLIC
)
263 HTTP_REQUEST_ME(enableCookies
, ZEND_ACC_PUBLIC
)
264 #if HTTP_CURL_VERSION(7,14,1)
265 HTTP_REQUEST_ME(resetCookies
, ZEND_ACC_PUBLIC
)
268 HTTP_REQUEST_ME(setMethod
, ZEND_ACC_PUBLIC
)
269 HTTP_REQUEST_ME(getMethod
, ZEND_ACC_PUBLIC
)
271 HTTP_REQUEST_ME(setUrl
, ZEND_ACC_PUBLIC
)
272 HTTP_REQUEST_ME(getUrl
, ZEND_ACC_PUBLIC
)
274 HTTP_REQUEST_ME(setContentType
, ZEND_ACC_PUBLIC
)
275 HTTP_REQUEST_ME(getContentType
, ZEND_ACC_PUBLIC
)
277 HTTP_REQUEST_ME(setQueryData
, ZEND_ACC_PUBLIC
)
278 HTTP_REQUEST_ME(getQueryData
, ZEND_ACC_PUBLIC
)
279 HTTP_REQUEST_ME(addQueryData
, ZEND_ACC_PUBLIC
)
281 HTTP_REQUEST_ME(setPostFields
, ZEND_ACC_PUBLIC
)
282 HTTP_REQUEST_ME(getPostFields
, ZEND_ACC_PUBLIC
)
283 HTTP_REQUEST_ME(addPostFields
, ZEND_ACC_PUBLIC
)
285 HTTP_REQUEST_ME(setRawPostData
, ZEND_ACC_PUBLIC
)
286 HTTP_REQUEST_ME(getRawPostData
, ZEND_ACC_PUBLIC
)
287 HTTP_REQUEST_ME(addRawPostData
, ZEND_ACC_PUBLIC
)
289 HTTP_REQUEST_ME(setPostFiles
, ZEND_ACC_PUBLIC
)
290 HTTP_REQUEST_ME(addPostFile
, ZEND_ACC_PUBLIC
)
291 HTTP_REQUEST_ME(getPostFiles
, ZEND_ACC_PUBLIC
)
293 HTTP_REQUEST_ME(setPutFile
, ZEND_ACC_PUBLIC
)
294 HTTP_REQUEST_ME(getPutFile
, ZEND_ACC_PUBLIC
)
296 HTTP_REQUEST_ME(setPutData
, ZEND_ACC_PUBLIC
)
297 HTTP_REQUEST_ME(getPutData
, ZEND_ACC_PUBLIC
)
298 HTTP_REQUEST_ME(addPutData
, ZEND_ACC_PUBLIC
)
300 HTTP_REQUEST_ME(send
, ZEND_ACC_PUBLIC
)
302 HTTP_REQUEST_ME(getResponseData
, ZEND_ACC_PUBLIC
)
303 HTTP_REQUEST_ME(getResponseHeader
, ZEND_ACC_PUBLIC
)
304 HTTP_REQUEST_ME(getResponseCookies
, ZEND_ACC_PUBLIC
)
305 HTTP_REQUEST_ME(getResponseCode
, ZEND_ACC_PUBLIC
)
306 HTTP_REQUEST_ME(getResponseStatus
, ZEND_ACC_PUBLIC
)
307 HTTP_REQUEST_ME(getResponseBody
, ZEND_ACC_PUBLIC
)
308 HTTP_REQUEST_ME(getResponseInfo
, ZEND_ACC_PUBLIC
)
309 HTTP_REQUEST_ME(getResponseMessage
, ZEND_ACC_PUBLIC
)
310 HTTP_REQUEST_ME(getRawResponseMessage
, ZEND_ACC_PUBLIC
)
311 HTTP_REQUEST_ME(getRequestMessage
, ZEND_ACC_PUBLIC
)
312 HTTP_REQUEST_ME(getRawRequestMessage
, ZEND_ACC_PUBLIC
)
313 HTTP_REQUEST_ME(getHistory
, ZEND_ACC_PUBLIC
)
314 HTTP_REQUEST_ME(clearHistory
, ZEND_ACC_PUBLIC
)
316 HTTP_REQUEST_ALIAS(get
, http_get
)
317 HTTP_REQUEST_ALIAS(head
, http_head
)
318 HTTP_REQUEST_ALIAS(postData
, http_post_data
)
319 HTTP_REQUEST_ALIAS(postFields
, http_post_fields
)
320 HTTP_REQUEST_ALIAS(putData
, http_put_data
)
321 HTTP_REQUEST_ALIAS(putFile
, http_put_file
)
322 HTTP_REQUEST_ALIAS(putStream
, http_put_stream
)
324 HTTP_REQUEST_ALIAS(methodRegister
, http_request_method_register
)
325 HTTP_REQUEST_ALIAS(methodUnregister
, http_request_method_unregister
)
326 HTTP_REQUEST_ALIAS(methodName
, http_request_method_name
)
327 HTTP_REQUEST_ALIAS(methodExists
, http_request_method_exists
)
328 #ifdef HAVE_CURL_GETFORMDATA
329 HTTP_REQUEST_ALIAS(encodeBody
, http_request_body_encode
)
333 static zend_object_handlers http_request_object_handlers
;
335 PHP_MINIT_FUNCTION(http_request_object
)
337 HTTP_REGISTER_CLASS_EX(HttpRequest
, http_request_object
, NULL
, 0);
338 http_request_object_handlers
.clone_obj
= _http_request_object_clone_obj
;
340 DCL_PROP_N(PRIVATE
, options
);
341 DCL_PROP_N(PRIVATE
, postFields
);
342 DCL_PROP_N(PRIVATE
, postFiles
);
343 DCL_PROP_N(PRIVATE
, responseInfo
);
344 DCL_PROP_N(PRIVATE
, responseMessage
);
345 DCL_PROP(PRIVATE
, long, responseCode
, 0);
346 DCL_PROP(PRIVATE
, string
, responseStatus
, "");
347 DCL_PROP(PRIVATE
, long, method
, HTTP_GET
);
348 DCL_PROP(PRIVATE
, string
, url
, "");
349 DCL_PROP(PRIVATE
, string
, contentType
, "");
350 DCL_PROP(PRIVATE
, string
, rawPostData
, "");
351 DCL_PROP(PRIVATE
, string
, queryData
, "");
352 DCL_PROP(PRIVATE
, string
, putFile
, "");
353 DCL_PROP(PRIVATE
, string
, putData
, "");
354 DCL_PROP_N(PRIVATE
, history
);
355 DCL_PROP(PUBLIC
, bool, recordHistory
, 0);
359 * Request Method Constants
362 DCL_CONST(long, "METH_GET", HTTP_GET
);
363 DCL_CONST(long, "METH_HEAD", HTTP_HEAD
);
364 DCL_CONST(long, "METH_POST", HTTP_POST
);
365 DCL_CONST(long, "METH_PUT", HTTP_PUT
);
366 DCL_CONST(long, "METH_DELETE", HTTP_DELETE
);
367 DCL_CONST(long, "METH_OPTIONS", HTTP_OPTIONS
);
368 DCL_CONST(long, "METH_TRACE", HTTP_TRACE
);
369 DCL_CONST(long, "METH_CONNECT", HTTP_CONNECT
);
370 /* WebDAV - RFC 2518 */
371 DCL_CONST(long, "METH_PROPFIND", HTTP_PROPFIND
);
372 DCL_CONST(long, "METH_PROPPATCH", HTTP_PROPPATCH
);
373 DCL_CONST(long, "METH_MKCOL", HTTP_MKCOL
);
374 DCL_CONST(long, "METH_COPY", HTTP_COPY
);
375 DCL_CONST(long, "METH_MOVE", HTTP_MOVE
);
376 DCL_CONST(long, "METH_LOCK", HTTP_LOCK
);
377 DCL_CONST(long, "METH_UNLOCK", HTTP_UNLOCK
);
378 /* WebDAV Versioning - RFC 3253 */
379 DCL_CONST(long, "METH_VERSION_CONTROL", HTTP_VERSION_CONTROL
);
380 DCL_CONST(long, "METH_REPORT", HTTP_REPORT
);
381 DCL_CONST(long, "METH_CHECKOUT", HTTP_CHECKOUT
);
382 DCL_CONST(long, "METH_CHECKIN", HTTP_CHECKIN
);
383 DCL_CONST(long, "METH_UNCHECKOUT", HTTP_UNCHECKOUT
);
384 DCL_CONST(long, "METH_MKWORKSPACE", HTTP_MKWORKSPACE
);
385 DCL_CONST(long, "METH_UPDATE", HTTP_UPDATE
);
386 DCL_CONST(long, "METH_LABEL", HTTP_LABEL
);
387 DCL_CONST(long, "METH_MERGE", HTTP_MERGE
);
388 DCL_CONST(long, "METH_BASELINE_CONTROL", HTTP_BASELINE_CONTROL
);
389 DCL_CONST(long, "METH_MKACTIVITY", HTTP_MKACTIVITY
);
390 /* WebDAV Access Control - RFC 3744 */
391 DCL_CONST(long, "METH_ACL", HTTP_ACL
);
394 * HTTP Protocol Version Constants
396 DCL_CONST(long, "VERSION_1_0", CURL_HTTP_VERSION_1_0
);
397 DCL_CONST(long, "VERSION_1_1", CURL_HTTP_VERSION_1_1
);
398 DCL_CONST(long, "VERSION_NONE", CURL_HTTP_VERSION_NONE
); /* to be removed */
399 DCL_CONST(long, "VERSION_ANY", CURL_HTTP_VERSION_NONE
);
402 * SSL Version Constants
404 DCL_CONST(long, "SSL_VERSION_TLSv1", CURL_SSLVERSION_TLSv1
);
405 DCL_CONST(long, "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2
);
406 DCL_CONST(long, "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3
);
407 DCL_CONST(long, "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT
);
412 DCL_CONST(long, "IPRESOLVE_V4", CURL_IPRESOLVE_V4
);
413 DCL_CONST(long, "IPRESOLVE_V6", CURL_IPRESOLVE_V6
);
414 DCL_CONST(long, "IPRESOLVE_ANY", CURL_IPRESOLVE_WHATEVER
);
419 DCL_CONST(long, "AUTH_BASIC", CURLAUTH_BASIC
);
420 DCL_CONST(long, "AUTH_DIGEST", CURLAUTH_DIGEST
);
421 DCL_CONST(long, "AUTH_NTLM", CURLAUTH_NTLM
);
422 DCL_CONST(long, "AUTH_GSSNEG", CURLAUTH_GSSNEGOTIATE
);
423 DCL_CONST(long, "AUTH_ANY", CURLAUTH_ANY
);
426 * Proxy Type Constants
428 # if HTTP_CURL_VERSION(7,15,2)
429 DCL_CONST(long, "PROXY_SOCKS4", CURLPROXY_SOCKS4
);
431 DCL_CONST(long, "PROXY_SOCKS5", CURLPROXY_SOCKS5
);
432 DCL_CONST(long, "PROXY_HTTP", CURLPROXY_HTTP
);
438 zend_object_value
_http_request_object_new(zend_class_entry
*ce TSRMLS_DC
)
440 return http_request_object_new_ex(ce
, NULL
, NULL
);
443 zend_object_value
_http_request_object_new_ex(zend_class_entry
*ce
, CURL
*ch
, http_request_object
**ptr TSRMLS_DC
)
445 zend_object_value ov
;
446 http_request_object
*o
;
448 o
= ecalloc(1, sizeof(http_request_object
));
450 o
->request
= http_request_init_ex(NULL
, ch
, 0, NULL
);
456 ALLOC_HASHTABLE(OBJ_PROP(o
));
457 zend_hash_init(OBJ_PROP(o
), zend_hash_num_elements(&ce
->default_properties
), NULL
, ZVAL_PTR_DTOR
, 0);
458 zend_hash_copy(OBJ_PROP(o
), &ce
->default_properties
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
460 ov
.handle
= putObject(http_request_object
, o
);
461 ov
.handlers
= &http_request_object_handlers
;
466 zend_object_value
_http_request_object_clone_obj(zval
*this_ptr TSRMLS_DC
)
468 zend_object_value new_ov
;
469 http_request_object
*new_obj
;
470 getObject(http_request_object
, old_obj
);
472 new_ov
= http_request_object_new_ex(old_obj
->zo
.ce
, NULL
, &new_obj
);
473 if (old_obj
->request
->ch
) {
474 http_curl_init_ex(curl_easy_duphandle(old_obj
->request
->ch
), new_obj
->request
);
477 zend_objects_clone_members(&new_obj
->zo
, new_ov
, &old_obj
->zo
, Z_OBJ_HANDLE_P(this_ptr
) TSRMLS_CC
);
478 phpstr_append(&new_obj
->request
->conv
.request
, old_obj
->request
->conv
.request
.data
, old_obj
->request
->conv
.request
.used
);
479 phpstr_append(&new_obj
->request
->conv
.response
, old_obj
->request
->conv
.response
.data
, old_obj
->request
->conv
.response
.used
);
484 void _http_request_object_free(zend_object
*object TSRMLS_DC
)
486 http_request_object
*o
= (http_request_object
*) object
;
488 http_request_free(&o
->request
);
492 #define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
493 static inline void _http_request_object_check_request_content_type(zval
*this_ptr TSRMLS_DC
)
495 zval
*ctype
= GET_PROP(contentType
);
497 if (Z_STRLEN_P(ctype
)) {
498 zval
**headers
, *opts
= GET_PROP(options
);
500 if ( (Z_TYPE_P(opts
) == IS_ARRAY
) &&
501 (SUCCESS
== zend_hash_find(Z_ARRVAL_P(opts
), "headers", sizeof("headers"), (void *) &headers
)) &&
502 (Z_TYPE_PP(headers
) == IS_ARRAY
)) {
505 /* only override if not already set */
506 if ((SUCCESS
!= zend_hash_find(Z_ARRVAL_PP(headers
), "Content-Type", sizeof("Content-Type"), (void *) &ct_header
))) {
507 add_assoc_stringl(*headers
, "Content-Type", Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
509 /* or not a string, zero length string or a string of spaces */
510 if ((Z_TYPE_PP(ct_header
) != IS_STRING
) || !Z_STRLEN_PP(ct_header
)) {
511 add_assoc_stringl(*headers
, "Content-Type", Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
513 int i
, only_space
= 1;
515 /* check for spaces only */
516 for (i
= 0; i
< Z_STRLEN_PP(ct_header
); ++i
) {
517 if (!HTTP_IS_CTYPE(space
, Z_STRVAL_PP(ct_header
)[i
])) {
523 add_assoc_stringl(*headers
, "Content-Type", Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
529 MAKE_STD_ZVAL(headers
);
531 add_assoc_stringl(headers
, "Content-Type", Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
532 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "addheaders", NULL
, headers
);
533 zval_ptr_dtor(&headers
);
538 STATUS
_http_request_object_requesthandler(http_request_object
*obj
, zval
*this_ptr TSRMLS_DC
)
540 STATUS status
= SUCCESS
;
542 http_request_reset(obj
->request
);
543 HTTP_CHECK_CURL_INIT(obj
->request
->ch
, http_curl_init(obj
->request
), return FAILURE
);
545 obj
->request
->url
= http_absolute_url(Z_STRVAL_P(GET_PROP(url
)));
547 switch (obj
->request
->meth
= Z_LVAL_P(GET_PROP(method
)))
555 zval
*put_file
= GET_PROP(putFile
);
557 http_request_object_check_request_content_type(getThis());
559 if (Z_STRLEN_P(put_file
)) {
560 php_stream_statbuf ssb
;
561 php_stream
*stream
= php_stream_open_wrapper_ex(Z_STRVAL_P(put_file
), "rb", REPORT_ERRORS
|ENFORCE_SAFE_MODE
, NULL
, HTTP_DEFAULT_STREAM_CONTEXT
);
563 if (stream
&& SUCCESS
== php_stream_stat(stream
, &ssb
)) {
564 obj
->request
->body
= http_request_body_init_ex(obj
->request
->body
, HTTP_REQUEST_BODY_UPLOADFILE
, stream
, ssb
.sb
.st_size
, 1);
569 zval
*put_data
= GET_PROP(putData
);
570 obj
->request
->body
= http_request_body_init_ex(obj
->request
->body
, HTTP_REQUEST_BODY_CSTRING
,
571 estrndup(Z_STRVAL_P(put_data
), Z_STRLEN_P(put_data
)), Z_STRLEN_P(put_data
), 1);
579 /* check for raw post data */
580 zval
*raw_data
= GET_PROP(rawPostData
);
582 if (Z_STRLEN_P(raw_data
)) {
583 http_request_object_check_request_content_type(getThis());
584 obj
->request
->body
= http_request_body_init_ex(obj
->request
->body
, HTTP_REQUEST_BODY_CSTRING
,
585 estrndup(Z_STRVAL_P(raw_data
), Z_STRLEN_P(raw_data
)), Z_STRLEN_P(raw_data
), 1);
587 zval
*zfields
= GET_PROP(postFields
), *zfiles
= GET_PROP(postFiles
);
591 fields
= (Z_TYPE_P(zfields
) == IS_ARRAY
) ? Z_ARRVAL_P(zfields
) : NULL
;
592 files
= (Z_TYPE_P(zfiles
) == IS_ARRAY
) ? Z_ARRVAL_P(zfiles
) : NULL
;
594 if ((fields
&& zend_hash_num_elements(fields
)) || (files
&& zend_hash_num_elements(files
))) {
595 if (!(obj
->request
->body
= http_request_body_fill(obj
->request
->body
, fields
, files
))) {
604 if (status
== SUCCESS
) {
605 zval
*qdata
= GET_PROP(queryData
);
606 zval
*options
= GET_PROP(options
);
608 if (Z_STRLEN_P(qdata
)) {
609 if (!strchr(obj
->request
->url
, '?')) {
610 strlcat(obj
->request
->url
, "?", HTTP_URL_MAXLEN
);
612 strlcat(obj
->request
->url
, "&", HTTP_URL_MAXLEN
);
614 strlcat(obj
->request
->url
, Z_STRVAL_P(qdata
), HTTP_URL_MAXLEN
);
617 http_request_prepare(obj
->request
, Z_ARRVAL_P(options
));
619 /* check if there's a onProgress method and add it as progress callback if one isn't already set */
620 if (zend_hash_exists(&Z_OBJCE_P(getThis())->function_table
, "onprogress", sizeof("onprogress"))) {
623 if ( (Z_TYPE_P(options
) != IS_ARRAY
)
624 || (SUCCESS
!= zend_hash_find(Z_ARRVAL_P(options
), "onprogress", sizeof("onprogress"), (void *) &entry
)
625 || (!zval_is_true(*entry
)))) {
628 ZVAL_ADDREF(getThis());
629 add_next_index_zval(pcb
, getThis());
630 add_next_index_stringl(pcb
, "onprogress", lenof("onprogress"), 1);
631 http_request_set_progress_callback(obj
->request
, pcb
);
640 STATUS
_http_request_object_responsehandler(http_request_object
*obj
, zval
*this_ptr TSRMLS_DC
)
646 /* always fetch info */
649 http_request_info(obj
->request
, Z_ARRVAL_P(info
));
650 SET_PROP(responseInfo
, info
);
651 zval_ptr_dtor(&info
);
653 /* parse response message */
654 phpstr_fix(&obj
->request
->conv
.request
);
655 phpstr_fix(&obj
->request
->conv
.response
);
657 if ((msg
= http_message_parse(PHPSTR_VAL(&obj
->request
->conv
.response
), PHPSTR_LEN(&obj
->request
->conv
.response
)))) {
660 if (zval_is_true(GET_PROP(recordHistory
))) {
661 zval
*hist
, *history
= GET_PROP(history
);
662 http_message
*response
= http_message_parse(PHPSTR_VAL(&obj
->request
->conv
.response
), PHPSTR_LEN(&obj
->request
->conv
.response
));
663 http_message
*request
= http_message_parse(PHPSTR_VAL(&obj
->request
->conv
.request
), PHPSTR_LEN(&obj
->request
->conv
.request
));
666 ZVAL_OBJVAL(hist
, http_message_object_new_ex(http_message_object_ce
, http_message_interconnect(response
, request
), NULL
), 0);
667 if (Z_TYPE_P(history
) == IS_OBJECT
) {
668 http_message_object_prepend(hist
, history
);
670 SET_PROP(history
, hist
);
671 zval_ptr_dtor(&hist
);
674 UPD_PROP(long, responseCode
, msg
->http
.info
.response
.code
);
675 UPD_PROP(string
, responseStatus
, STR_PTR(msg
->http
.info
.response
.status
));
677 MAKE_STD_ZVAL(message
);
678 ZVAL_OBJVAL(message
, http_message_object_new_ex(http_message_object_ce
, msg
, NULL
), 0);
679 SET_PROP(responseMessage
, message
);
680 zval_ptr_dtor(&message
);
684 /* update properties with empty values*/
687 MAKE_STD_ZVAL(znull
);
689 SET_PROP(responseMessage
, znull
);
690 zval_ptr_dtor(&znull
);
692 UPD_PROP(long, responseCode
, 0);
693 UPD_PROP(string
, responseStatus
, "");
695 /* append request message to history */
696 if (zval_is_true(GET_PROP(recordHistory
))) {
697 http_message
*request
;
699 if ((request
= http_message_parse(PHPSTR_VAL(&obj
->request
->conv
.request
), PHPSTR_LEN(&obj
->request
->conv
.request
)))) {
700 zval
*hist
, *history
= GET_PROP(history
);
703 ZVAL_OBJVAL(hist
, http_message_object_new_ex(http_message_object_ce
, request
, NULL
), 0);
704 if (Z_TYPE_P(history
) == IS_OBJECT
) {
705 http_message_object_prepend(hist
, history
);
707 SET_PROP(history
, hist
);
708 zval_ptr_dtor(&hist
);
715 if (!EG(exception
) && zend_hash_exists(&Z_OBJCE_P(getThis())->function_table
, "onfinish", sizeof("onfinish"))) {
718 MAKE_STD_ZVAL(param
);
719 ZVAL_BOOL(param
, ret
== SUCCESS
);
720 with_error_handling(EH_NORMAL
, NULL
) {
721 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "onfinish", NULL
, param
);
722 } end_error_handling();
723 zval_ptr_dtor(¶m
);
729 static int apply_pretty_key(void *pDest
, int num_args
, va_list args
, zend_hash_key
*hash_key
)
731 if (hash_key
->nKeyLength
> 1) {
732 hash_key
->h
= zend_get_hash_value(pretty_key(hash_key
->arKey
, hash_key
->nKeyLength
- 1, 1, 0), hash_key
->nKeyLength
);
734 return ZEND_HASH_APPLY_KEEP
;
737 #define http_request_object_set_options_subr(key, ow, pk) \
738 _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key), (ow), (pk))
739 static inline void _http_request_object_set_options_subr(INTERNAL_FUNCTION_PARAMETERS
, char *key
, size_t len
, int overwrite
, int prettify_keys
)
741 zval
*old_opts
, *new_opts
, *opts
= NULL
, **entry
= NULL
;
743 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a/!", &opts
)) {
747 MAKE_STD_ZVAL(new_opts
);
748 array_init(new_opts
);
749 old_opts
= GET_PROP(options
);
750 if (Z_TYPE_P(old_opts
) == IS_ARRAY
) {
751 array_copy(old_opts
, new_opts
);
754 if (prettify_keys
&& opts
) {
755 zend_hash_apply_with_arguments(Z_ARRVAL_P(opts
), apply_pretty_key
, 0);
757 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(new_opts
), key
, len
, (void *) &entry
)) {
759 zend_hash_clean(Z_ARRVAL_PP(entry
));
761 if (opts
&& zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
763 array_copy(opts
, *entry
);
765 array_merge(opts
, *entry
);
770 add_assoc_zval(new_opts
, key
, opts
);
772 SET_PROP(options
, new_opts
);
773 zval_ptr_dtor(&new_opts
);
778 #define http_request_object_get_options_subr(key) \
779 _http_request_get_options_subr(INTERNAL_FUNCTION_PARAM_PASSTHRU, (key), sizeof(key))
780 static inline void _http_request_get_options_subr(INTERNAL_FUNCTION_PARAMETERS
, char *key
, size_t len
)
784 if (return_value_used
) {
785 zval
*opts
, **options
;
787 opts
= GET_PROP(options
);
788 array_init(return_value
);
790 if ( (Z_TYPE_P(opts
) == IS_ARRAY
) &&
791 (SUCCESS
== zend_hash_find(Z_ARRVAL_P(opts
), key
, len
, (void *) &options
))) {
792 convert_to_array(*options
);
793 array_copy(*options
, return_value
);
799 /* ### USERLAND ### */
801 /* {{{ proto void HttpRequest::__construct([string url[, int request_method = HTTP_METH_GET[, array options]]])
803 * Instantiate a new HttpRequest object.
805 * Accepts a string as optional parameter containing the target request url.
806 * Additionally accepts an optional int parameter specifying the request method
807 * to use and an associative array as optional third parameter which will be
808 * passed to HttpRequest::setOptions().
810 * Throws HttpException.
812 PHP_METHOD(HttpRequest
, __construct
)
817 zval
*options
= NULL
;
820 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|sla!", &URL
, &URL_len
, &meth
, &options
)) {
822 UPD_STRL(url
, URL
, URL_len
);
825 UPD_PROP(long, method
, meth
);
828 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "setoptions", NULL
, options
);
835 /* {{{ proto bool HttpRequest::setOptions([array options])
837 * Set the request options to use. See http_get() for a full list of available options.
839 * Accepts an array as optional parameters, which values will overwrite the
840 * currently set request options. If the parameter is empty or omitted,
841 * the options of the HttpRequest object will be reset.
843 * Returns TRUE on success, or FALSE on failure.
845 PHP_METHOD(HttpRequest
, setOptions
)
850 zval
*opts
= NULL
, *old_opts
, *new_opts
, *add_opts
, **opt
;
852 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|a!/", &opts
)) {
856 MAKE_STD_ZVAL(new_opts
);
857 array_init(new_opts
);
859 if (!opts
|| !zend_hash_num_elements(Z_ARRVAL_P(opts
))) {
860 SET_PROP(options
, new_opts
);
861 zval_ptr_dtor(&new_opts
);
865 MAKE_STD_ZVAL(add_opts
);
866 array_init(add_opts
);
867 /* some options need extra attention -- thus cannot use array_merge() directly */
868 FOREACH_KEYVAL(pos
, opts
, key
, idx
, opt
) {
870 if (!strcmp(key
, "headers")) {
871 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "addheaders", NULL
, *opt
);
872 } else if (!strcmp(key
, "cookies")) {
873 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "addcookies", NULL
, *opt
);
874 } else if (!strcmp(key
, "ssl")) {
875 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "addssloptions", NULL
, *opt
);
876 } else if ((!strcasecmp(key
, "url")) || (!strcasecmp(key
, "uri"))) {
877 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "seturl", NULL
, *opt
);
878 } else if (!strcmp(key
, "method")) {
879 zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL
, "setmethod", NULL
, *opt
);
880 #if HTTP_CURL_VERSION(7,14,1)
881 } else if (!strcmp(key
, "resetcookies")) {
882 getObject(http_request_object
, obj
);
883 http_request_reset_cookies(obj
->request
, 0);
885 } else if (!strcmp(key
, "enablecookies")) {
886 getObject(http_request_object
, obj
);
887 http_request_enable_cookies(obj
->request
);
888 } else if (!strcasecmp(key
, "recordHistory")) {
889 UPD_PROP(bool, recordHistory
, 1);
892 add_assoc_zval(add_opts
, key
, *opt
);
899 old_opts
= GET_PROP(options
);
900 if (Z_TYPE_P(old_opts
) == IS_ARRAY
) {
901 array_copy(old_opts
, new_opts
);
903 array_merge(add_opts
, new_opts
);
904 SET_PROP(options
, new_opts
);
905 zval_ptr_dtor(&new_opts
);
906 zval_ptr_dtor(&add_opts
);
912 /* {{{ proto array HttpRequest::getOptions()
914 * Get currently set options.
916 * Returns an associative array containing currently set options.
918 PHP_METHOD(HttpRequest
, getOptions
)
922 if (return_value_used
) {
923 RETURN_PROP(options
);
928 /* {{{ proto bool HttpRequest::setSslOptions([array options])
932 * Accepts an associative array as parameter containing any SSL specific options.
933 * If the parameter is empty or omitted, the SSL options will be reset.
935 * Returns TRUE on success, or FALSE on failure.
937 PHP_METHOD(HttpRequest
, setSslOptions
)
939 http_request_object_set_options_subr("ssl", 1, 0);
943 /* {{{ proto bool HttpRequest::addSslOptions(array options)
945 * Set additional SSL options.
947 * Expects an associative array as parameter containing additional SSL specific options.
949 * Returns TRUE on success, or FALSE on failure.
951 PHP_METHOD(HttpRequest
, addSslOptions
)
953 http_request_object_set_options_subr("ssl", 0, 0);
957 /* {{{ proto array HttpRequest::getSslOtpions()
959 * Get previously set SSL options.
961 * Returns an associative array containing any previously set SSL options.
963 PHP_METHOD(HttpRequest
, getSslOptions
)
965 http_request_object_get_options_subr("ssl");
969 /* {{{ proto bool HttpRequest::addHeaders(array headers)
971 * Add request header name/value pairs.
973 * Expects an associative array as parameter containing additional header
976 * Returns TRUE on success, or FALSE on failure.
978 PHP_METHOD(HttpRequest
, addHeaders
)
980 http_request_object_set_options_subr("headers", 0, 1);
983 /* {{{ proto bool HttpRequest::setHeaders([array headers])
985 * Set request header name/value pairs.
987 * Accepts an associative array as parameter containing header name/value pairs.
988 * If the parameter is empty or omitted, all previously set headers will be unset.
990 * Returns TRUE on success, or FALSE on failure.
992 PHP_METHOD(HttpRequest
, setHeaders
)
994 http_request_object_set_options_subr("headers", 1, 1);
998 /* {{{ proto array HttpRequest::getHeaders()
1000 * Get previously set request headers.
1002 * Returns an associative array containing all currently set headers.
1004 PHP_METHOD(HttpRequest
, getHeaders
)
1006 http_request_object_get_options_subr("headers");
1010 /* {{{ proto bool HttpRequest::setCookies([array cookies])
1014 * Accepts an associative array as parameter containing cookie name/value pairs.
1015 * If the parameter is empty or omitted, all previously set cookies will be unset.
1017 * Returns TRUE on success, or FALSE on failure.
1019 PHP_METHOD(HttpRequest
, setCookies
)
1021 http_request_object_set_options_subr("cookies", 1, 0);
1025 /* {{{ proto bool HttpRequest::addCookies(array cookies)
1029 * Expects an associative array as parameter containing any cookie name/value
1032 * Returns TRUE on success, or FALSE on failure.
1034 PHP_METHOD(HttpRequest
, addCookies
)
1036 http_request_object_set_options_subr("cookies", 0, 0);
1040 /* {{{ proto array HttpRequest::getCookies()
1042 * Get previously set cookies.
1044 * Returns an associative array containing any previously set cookies.
1046 PHP_METHOD(HttpRequest
, getCookies
)
1048 http_request_object_get_options_subr("cookies");
1052 /* {{{ proto bool HttpRequest::enableCookies()
1054 * Enable automatic sending of received cookies.
1055 * Note that cuutomly set cookies will be sent anyway.
1057 PHP_METHOD(HttpRequest
, enableCookies
)
1060 getObject(http_request_object
, obj
);
1061 RETURN_SUCCESS(http_request_enable_cookies(obj
->request
));
1067 /* {{{ proto bool HttpRequest::resetCookies([bool session_only = FALSE])
1069 * Reset all automatically received/sent cookies.
1070 * Note that customly set cookies are not affected.
1072 * Accepts an optional bool parameter specifying
1073 * whether only session cookies should be reset
1074 * (needs libcurl >= v7.15.4, else libcurl >= v7.14.1).
1076 * Returns TRUE on success, or FALSE on failure.
1078 PHP_METHOD(HttpRequest
, resetCookies
)
1080 zend_bool session_only
= 0;
1081 getObject(http_request_object
, obj
);
1083 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|b", &session_only
)) {
1086 RETURN_SUCCESS(http_request_reset_cookies(obj
->request
, session_only
));
1090 /* {{{ proto bool HttpRequest::setUrl(string url)
1092 * Set the request URL.
1094 * Expects a string as parameter specifying the request url.
1096 * Returns TRUE on success, or FALSE on failure.
1098 PHP_METHOD(HttpRequest
, setUrl
)
1103 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &URL
, &URL_len
)) {
1107 UPD_STRL(url
, URL
, URL_len
);
1112 /* {{{ proto string HttpRequest::getUrl()
1114 * Get the previously set request URL.
1116 * Returns the currently set request url as string.
1118 PHP_METHOD(HttpRequest
, getUrl
)
1122 if (return_value_used
) {
1128 /* {{{ proto bool HttpRequest::setMethod(int request_method)
1130 * Set the request method.
1132 * Expects an int as parameter specifying the request method to use.
1133 * In PHP 5.1+ HttpRequest::METH_*, otherwise the HTTP_METH_* constants can be used.
1135 * Returns TRUE on success, or FALSE on failure.
1137 PHP_METHOD(HttpRequest
, setMethod
)
1141 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &meth
)) {
1145 UPD_PROP(long, method
, meth
);
1150 /* {{{ proto int HttpRequest::getMethod()
1152 * Get the previously set request method.
1154 * Returns the currently set request method.
1156 PHP_METHOD(HttpRequest
, getMethod
)
1160 if (return_value_used
) {
1161 RETURN_PROP(method
);
1166 /* {{{ proto bool HttpRequest::setContentType(string content_type)
1168 * Set the content type the post request should have.
1170 * Expects a string as parameters containing the content type of the request
1171 * (primary/secondary).
1173 * Returns TRUE on success, or FALSE if the content type does not seem to
1174 * contain a primary and a secondary part.
1176 PHP_METHOD(HttpRequest
, setContentType
)
1181 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &ctype
, &ct_len
)) {
1186 HTTP_CHECK_CONTENT_TYPE(ctype
, RETURN_FALSE
);
1188 UPD_STRL(contentType
, ctype
, ct_len
);
1193 /* {{{ proto string HttpRequest::getContentType()
1195 * Get the previously content type.
1197 * Returns the previously set content type as string.
1199 PHP_METHOD(HttpRequest
, getContentType
)
1203 if (return_value_used
) {
1204 RETURN_PROP(contentType
);
1209 /* {{{ proto bool HttpRequest::setQueryData([mixed query_data])
1211 * Set the URL query parameters to use, overwriting previously set query parameters.
1212 * Affects any request types.
1214 * Accepts a string or associative array parameter containing the pre-encoded
1215 * query string or to be encoded query fields. If the parameter is empty or
1216 * omitted, the query data will be unset.
1218 * Returns TRUE on success, or FALSE on failure.
1220 PHP_METHOD(HttpRequest
, setQueryData
)
1224 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z!", &qdata
)) {
1228 if ((!qdata
) || Z_TYPE_P(qdata
) == IS_NULL
) {
1229 UPD_STRL(queryData
, "", 0);
1230 } else if ((Z_TYPE_P(qdata
) == IS_ARRAY
) || (Z_TYPE_P(qdata
) == IS_OBJECT
)) {
1231 char *query_data
= NULL
;
1233 if (SUCCESS
!= http_urlencode_hash(HASH_OF(qdata
), &query_data
)) {
1237 UPD_PROP(string
, queryData
, query_data
);
1242 convert_to_string_ex(&qdata
);
1243 UPD_STRL(queryData
, Z_STRVAL_P(qdata
), Z_STRLEN_P(qdata
));
1244 if (orig
!= qdata
) {
1245 zval_ptr_dtor(&qdata
);
1252 /* {{{ proto string HttpRequest::getQueryData()
1254 * Get the current query data in form of an urlencoded query string.
1256 * Returns a string containing the urlencoded query.
1258 PHP_METHOD(HttpRequest
, getQueryData
)
1262 if (return_value_used
) {
1263 RETURN_PROP(queryData
);
1268 /* {{{ proto bool HttpRequest::addQueryData(array query_params)
1270 * Add parameters to the query parameter list, leaving previously set unchanged.
1271 * Affects any request type.
1273 * Expects an associative array as parameter containing the query fields to add.
1275 * Returns TRUE on success, or FALSE on failure.
1277 PHP_METHOD(HttpRequest
, addQueryData
)
1279 zval
*qdata
, *old_qdata
;
1280 char *query_data
= NULL
;
1281 size_t query_data_len
= 0;
1283 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a/", &qdata
)) {
1287 old_qdata
= GET_PROP(queryData
);
1289 if (SUCCESS
!= http_urlencode_hash_ex(HASH_OF(qdata
), 1, Z_STRVAL_P(old_qdata
), Z_STRLEN_P(old_qdata
), &query_data
, &query_data_len
)) {
1293 UPD_STRL(queryData
, query_data
, query_data_len
);
1300 /* {{{ proto bool HttpRequest::addPostFields(array post_data)
1302 * Adds POST data entries, leaving previously set unchanged, unless a
1303 * post entry with the same name already exists.
1304 * Affects only POST and custom requests.
1306 * Expects an associative array as parameter containing the post fields.
1308 * Returns TRUE on success, or FALSE on failure.
1310 PHP_METHOD(HttpRequest
, addPostFields
)
1312 zval
*post_data
, *old_post
, *new_post
;
1314 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a/", &post_data
)) {
1318 if (zend_hash_num_elements(Z_ARRVAL_P(post_data
))) {
1319 MAKE_STD_ZVAL(new_post
);
1320 array_init(new_post
);
1321 old_post
= GET_PROP(postFields
);
1322 if (Z_TYPE_P(old_post
) == IS_ARRAY
) {
1323 array_copy(old_post
, new_post
);
1325 array_merge(post_data
, new_post
);
1326 SET_PROP(postFields
, new_post
);
1327 zval_ptr_dtor(&new_post
);
1334 /* {{{ proto bool HttpRequest::setPostFields([array post_data])
1336 * Set the POST data entries, overwriting previously set POST data.
1337 * Affects only POST and custom requests.
1339 * Accepts an associative array as parameter containing the post fields.
1340 * If the parameter is empty or omitted, the post data will be unset.
1342 * Returns TRUE on success, or FALSE on failure.
1344 PHP_METHOD(HttpRequest
, setPostFields
)
1346 zval
*post
, *post_data
= NULL
;
1348 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a/!", &post_data
)) {
1352 MAKE_STD_ZVAL(post
);
1354 if (post_data
&& zend_hash_num_elements(Z_ARRVAL_P(post_data
))) {
1355 array_copy(post_data
, post
);
1357 SET_PROP(postFields
, post
);
1358 zval_ptr_dtor(&post
);
1364 /* {{{ proto array HttpRequest::getPostFields()
1366 * Get previously set POST data.
1368 * Returns the currently set post fields as associative array.
1370 PHP_METHOD(HttpRequest
, getPostFields
)
1374 if (return_value_used
) {
1375 RETURN_PROP(postFields
);
1380 /* {{{ proto bool HttpRequest::setRawPostData([string raw_post_data])
1382 * Set raw post data to send, overwriting previously set raw post data. Don't
1383 * forget to specify a content type. Affects only POST and custom requests.
1384 * Only either post fields or raw post data can be used for each request.
1385 * Raw post data has higher precedence and will be used even if post fields
1388 * Accepts a string as parameter containing the *raw* post data.
1390 * Returns TRUE on success, or FALSE on failure.
1392 PHP_METHOD(HttpRequest
, setRawPostData
)
1394 char *raw_data
= NULL
;
1397 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &raw_data
, &data_len
)) {
1405 UPD_STRL(rawPostData
, raw_data
, data_len
);
1410 /* {{{ proto bool HttpRequest::addRawPostData(string raw_post_data)
1412 * Add raw post data, leaving previously set raw post data unchanged.
1413 * Affects only POST and custom requests.
1415 * Expects a string as parameter containing the raw post data to concatenate.
1417 * Returns TRUE on success, or FALSE on failure.
1419 PHP_METHOD(HttpRequest
, addRawPostData
)
1424 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &raw_data
, &data_len
)) {
1429 zval
*data
= GET_PROP(rawPostData
);
1431 if (Z_STRLEN_P(data
)) {
1432 Z_STRVAL_P(data
) = erealloc(Z_STRVAL_P(data
), (Z_STRLEN_P(data
) += data_len
) + 1);
1433 Z_STRVAL_P(data
)[Z_STRLEN_P(data
)] = '\0';
1434 memcpy(Z_STRVAL_P(data
) + Z_STRLEN_P(data
) - data_len
, raw_data
, data_len
);
1436 UPD_STRL(putData
, raw_data
, data_len
);
1444 /* {{{ proto string HttpRequest::getRawPostData()
1446 * Get previously set raw post data.
1448 * Returns a string containing the currently set raw post data.
1450 PHP_METHOD(HttpRequest
, getRawPostData
)
1454 if (return_value_used
) {
1455 RETURN_PROP(rawPostData
);
1460 /* {{{ proto bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
1462 * Add a file to the POST request, leaving previously set files unchanged.
1463 * Affects only POST and custom requests. Cannot be used with raw post data.
1465 * Expects a string parameter containing the form element name, and a string
1466 * paremeter containing the path to the file which should be uploaded.
1467 * Additionally accepts an optional string parameter which should contain
1468 * the content type of the file.
1470 * Returns TRUE on success, or FALSE if the content type seems not to contain a
1471 * primary and a secondary content type part.
1473 PHP_METHOD(HttpRequest
, addPostFile
)
1475 zval
*entry
, *old_post
, *new_post
;
1476 char *name
, *file
, *type
= NULL
;
1477 int name_len
, file_len
, type_len
= 0;
1479 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "ss|s", &name
, &name_len
, &file
, &file_len
, &type
, &type_len
)) {
1484 HTTP_CHECK_CONTENT_TYPE(type
, RETURN_FALSE
);
1486 type
= "application/x-octetstream";
1487 type_len
= sizeof("application/x-octetstream") - 1;
1490 MAKE_STD_ZVAL(entry
);
1493 add_assoc_stringl(entry
, "name", name
, name_len
, 1);
1494 add_assoc_stringl(entry
, "type", type
, type_len
, 1);
1495 add_assoc_stringl(entry
, "file", file
, file_len
, 1);
1497 MAKE_STD_ZVAL(new_post
);
1498 array_init(new_post
);
1499 old_post
= GET_PROP(postFiles
);
1500 if (Z_TYPE_P(old_post
) == IS_ARRAY
) {
1501 array_copy(old_post
, new_post
);
1503 add_next_index_zval(new_post
, entry
);
1504 SET_PROP(postFiles
, new_post
);
1505 zval_ptr_dtor(&new_post
);
1511 /* {{{ proto bool HttpRequest::setPostFiles([array post_files])
1513 * Set files to post, overwriting previously set post files.
1514 * Affects only POST and requests. Cannot be used with raw post data.
1516 * Accepts an array containing the files to post. Each entry should be an
1517 * associative array with "name", "file" and "type" keys. If the parameter
1518 * is empty or omitted the post files will be unset.
1520 * Returns TRUE on success, or FALSE on failure.
1522 PHP_METHOD(HttpRequest
, setPostFiles
)
1524 zval
*files
= NULL
, *post
;
1526 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "a!/", &files
)) {
1530 MAKE_STD_ZVAL(post
);
1532 if (files
&& (Z_TYPE_P(files
) == IS_ARRAY
)) {
1533 array_copy(files
, post
);
1535 SET_PROP(postFiles
, post
);
1536 zval_ptr_dtor(&post
);
1542 /* {{{ proto array HttpRequest::getPostFiles()
1544 * Get all previously added POST files.
1546 * Returns an array containing currently set post files.
1548 PHP_METHOD(HttpRequest
, getPostFiles
)
1552 if (return_value_used
) {
1553 RETURN_PROP(postFiles
);
1558 /* {{{ proto bool HttpRequest::setPutFile([string file])
1560 * Set file to put. Affects only PUT requests.
1562 * Accepts a string as parameter referencing the path to file.
1563 * If the parameter is empty or omitted the put file will be unset.
1565 * Returns TRUE on success, or FALSE on failure.
1567 PHP_METHOD(HttpRequest
, setPutFile
)
1572 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &file
, &file_len
)) {
1576 UPD_STRL(putFile
, file
, file_len
);
1581 /* {{{ proto string HttpRequest::getPutFile()
1583 * Get previously set put file.
1585 * Returns a string containing the path to the currently set put file.
1587 PHP_METHOD(HttpRequest
, getPutFile
)
1591 if (return_value_used
) {
1592 RETURN_PROP(putFile
);
1597 /* {{{ proto bool HttpRequest::setPutData([string put_data])
1599 * Set PUT data to send, overwriting previously set PUT data.
1600 * Affects only PUT requests.
1601 * Only either PUT data or PUT file can be used for each request.
1602 * PUT data has higher precedence and will be used even if a PUT
1605 * Accepts a string as parameter containing the data to upload.
1607 * Returns TRUE on success, or FALSE on failure.
1609 PHP_METHOD(HttpRequest
, setPutData
)
1611 char *put_data
= NULL
;
1614 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &put_data
, &data_len
)) {
1622 UPD_STRL(putData
, put_data
, data_len
);
1627 /* {{{ proto bool HttpRequest::addPutData(string put_data)
1629 * Add PUT data, leaving previously set PUT data unchanged.
1630 * Affects only PUT requests.
1632 * Expects a string as parameter containing the data to concatenate.
1634 * Returns TRUE on success, or FALSE on failure.
1636 PHP_METHOD(HttpRequest
, addPutData
)
1641 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &put_data
, &data_len
)) {
1646 zval
*data
= GET_PROP(putData
);
1648 if (Z_STRLEN_P(data
)) {
1649 Z_STRVAL_P(data
) = erealloc(Z_STRVAL_P(data
), (Z_STRLEN_P(data
) += data_len
) + 1);
1650 Z_STRVAL_P(data
)[Z_STRLEN_P(data
)] = '\0';
1651 memcpy(Z_STRVAL_P(data
) + Z_STRLEN_P(data
) - data_len
, put_data
, data_len
);
1653 UPD_STRL(putData
, put_data
, data_len
);
1661 /* {{{ proto string HttpRequest::getPutData()
1663 * Get previously set PUT data.
1665 * Returns a string containing the currently set raw post data.
1667 PHP_METHOD(HttpRequest
, getPutData
)
1671 if (return_value_used
) {
1672 RETURN_PROP(putData
);
1677 /* {{{ proto array HttpRequest::getResponseData()
1679 * Get all response data after the request has been sent.
1681 * Returns an associative array with the key "headers" containing an associative
1682 * array holding all response headers, as well as the key "body" containing a
1683 * string with the response body.
1685 * If redirects were allowed and several responses were received, the data
1686 * references the last received response.
1688 PHP_METHOD(HttpRequest
, getResponseData
)
1692 if (return_value_used
) {
1695 zval
*headers
, *message
= GET_PROP(responseMessage
);
1697 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1698 getObjectEx(http_message_object
, msg
, message
);
1700 array_init(return_value
);
1702 MAKE_STD_ZVAL(headers
);
1703 array_init(headers
);
1704 zend_hash_copy(Z_ARRVAL_P(headers
), &msg
->message
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
1705 add_assoc_zval(return_value
, "headers", headers
);
1707 phpstr_data(PHPSTR(msg
->message
), &body
, &body_len
);
1708 add_assoc_stringl(return_value
, "body", body
, body_len
, 0);
1714 /* {{{ proto mixed HttpRequest::getResponseHeader([string name])
1716 * Get response header(s) after the request has been sent.
1718 * Accepts an string as optional parameter specifying a certain header to read.
1719 * If the parameter is empty or omitted all response headers will be returned.
1721 * Returns either a string with the value of the header matching name if requested,
1722 * FALSE on failure, or an associative array containing all response headers.
1724 * If redirects were allowed and several responses were received, the data
1725 * references the last received response.
1727 PHP_METHOD(HttpRequest
, getResponseHeader
)
1729 if (return_value_used
) {
1731 char *header_name
= NULL
;
1734 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &header_name
, &header_len
)) {
1735 zval
*message
= GET_PROP(responseMessage
);
1737 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1738 getObjectEx(http_message_object
, msg
, message
);
1741 if ((header
= http_message_header_ex(msg
->message
, pretty_key(header_name
, header_len
, 1, 1), header_len
+ 1, 0))) {
1742 RETURN_ZVAL(header
, 1, 1);
1745 array_init(return_value
);
1746 zend_hash_copy(Z_ARRVAL_P(return_value
), &msg
->message
->hdrs
, (copy_ctor_func_t
) zval_add_ref
, NULL
, sizeof(zval
*));
1756 /* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
1758 * Get response cookie(s) after the request has been sent.
1760 * Returns an array of stdClass objects like http_parse_cookie would return.
1762 * If redirects were allowed and several responses were received, the data
1763 * references the last received response.
1765 PHP_METHOD(HttpRequest
, getResponseCookies
)
1767 if (return_value_used
) {
1769 zval
*allowed_extras_array
= NULL
;
1771 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|la!", &flags
, &allowed_extras_array
)) {
1774 char *key
= NULL
, **allowed_extras
= NULL
;
1775 zval
**header
= NULL
, **entry
= NULL
, *message
= GET_PROP(responseMessage
);
1776 HashPosition pos
, pos1
, pos2
;
1778 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1779 getObjectEx(http_message_object
, msg
, message
);
1781 array_init(return_value
);
1783 if (allowed_extras_array
) {
1784 allowed_extras
= ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array
)) + 1, sizeof(char *));
1785 FOREACH_VAL(pos
, allowed_extras_array
, entry
) {
1786 ZVAL_ADDREF(*entry
);
1787 convert_to_string_ex(entry
);
1788 allowed_extras
[i
++] = estrndup(Z_STRVAL_PP(entry
), Z_STRLEN_PP(entry
));
1789 zval_ptr_dtor(entry
);
1793 FOREACH_HASH_KEYVAL(pos1
, &msg
->message
->hdrs
, key
, idx
, header
) {
1794 if (key
&& !strcasecmp(key
, "Set-Cookie")) {
1795 http_cookie_list list
;
1797 if (Z_TYPE_PP(header
) == IS_ARRAY
) {
1798 zval
**single_header
;
1800 FOREACH_VAL(pos2
, *header
, single_header
) {
1801 ZVAL_ADDREF(*single_header
);
1802 convert_to_string_ex(single_header
);
1803 if (http_parse_cookie_ex(&list
, Z_STRVAL_PP(single_header
), flags
, allowed_extras
)) {
1806 MAKE_STD_ZVAL(cookie
);
1807 object_init(cookie
);
1808 http_cookie_list_tostruct(&list
, cookie
);
1809 add_next_index_zval(return_value
, cookie
);
1810 http_cookie_list_dtor(&list
);
1812 zval_ptr_dtor(single_header
);
1815 ZVAL_ADDREF(*header
);
1816 convert_to_string_ex(header
);
1817 if (http_parse_cookie_ex(&list
, Z_STRVAL_PP(header
), flags
, allowed_extras
)) {
1820 MAKE_STD_ZVAL(cookie
);
1821 object_init(cookie
);
1822 http_cookie_list_tostruct(&list
, cookie
);
1823 add_next_index_zval(return_value
, cookie
);
1824 http_cookie_list_dtor(&list
);
1826 zval_ptr_dtor(header
);
1833 if (allowed_extras
) {
1834 for (i
= 0; allowed_extras
[i
]; ++i
) {
1835 efree(allowed_extras
[i
]);
1837 efree(allowed_extras
);
1848 /* {{{ proto string HttpRequest::getResponseBody()
1850 * Get the response body after the request has been sent.
1852 * Returns a string containing the response body.
1854 * If redirects were allowed and several responses were received, the data
1855 * references the last received response.
1857 PHP_METHOD(HttpRequest
, getResponseBody
)
1861 if (return_value_used
) {
1862 zval
*message
= GET_PROP(responseMessage
);
1864 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1865 getObjectEx(http_message_object
, msg
, message
);
1866 RETURN_PHPSTR_DUP(&msg
->message
->body
);
1874 /* {{{ proto int HttpRequest::getResponseCode()
1876 * Get the response code after the request has been sent.
1878 * Returns an int representing the response code.
1880 * If redirects were allowed and several responses were received, the data
1881 * references the last received response.
1883 PHP_METHOD(HttpRequest
, getResponseCode
)
1887 if (return_value_used
) {
1888 RETURN_PROP(responseCode
);
1893 /* {{{ proto string HttpRequest::getResponseStatus()
1895 * Get the response status (i.e. the string after the response code) after the message has been sent.
1897 * Returns a string containing the response status text.
1899 PHP_METHOD(HttpRequest
, getResponseStatus
)
1903 if (return_value_used
) {
1904 RETURN_PROP(responseStatus
);
1909 /* {{{ proto mixed HttpRequest::getResponseInfo([string name])
1911 * Get response info after the request has been sent.
1912 * See http_get() for a full list of returned info.
1914 * Accepts a string as optional parameter specifying the info to read.
1915 * If the parameter is empty or omitted, an associative array containing
1916 * all available info will be returned.
1918 * Returns either a scalar containing the value of the info matching name if
1919 * requested, FALSE on failure, or an associative array containing all
1922 * If redirects were allowed and several responses were received, the data
1923 * references the last received response.
1925 PHP_METHOD(HttpRequest
, getResponseInfo
)
1927 if (return_value_used
) {
1928 zval
*info
, **infop
;
1929 char *info_name
= NULL
;
1932 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s", &info_name
, &info_len
)) {
1936 info
= GET_PROP(responseInfo
);
1938 if (Z_TYPE_P(info
) != IS_ARRAY
) {
1942 if (info_len
&& info_name
) {
1943 if (SUCCESS
== zend_hash_find(Z_ARRVAL_P(info
), pretty_key(info_name
, info_len
, 0, 0), info_len
+ 1, (void *) &infop
)) {
1944 RETURN_ZVAL(*infop
, 1, 0);
1946 http_error_ex(HE_NOTICE
, HTTP_E_INVALID_PARAM
, "Could not find response info named %s", info_name
);
1950 RETURN_ZVAL(info
, 1, 0);
1956 /* {{{ proto HttpMessage HttpRequest::getResponseMessage()
1958 * Get the full response as HttpMessage object after the request has been sent.
1960 * Returns an HttpMessage object of the response.
1962 * If redirects were allowed and several responses were received, the data
1963 * references the last received response. Use HttpMessage::getParentMessage()
1964 * to access the data of previously received responses within this request
1967 * Throws HttpException, HttpRuntimeException.
1969 PHP_METHOD(HttpRequest
, getResponseMessage
)
1974 SET_EH_THROW_HTTP();
1975 message
= GET_PROP(responseMessage
);
1976 if (Z_TYPE_P(message
) == IS_OBJECT
) {
1977 RETVAL_OBJECT(message
, 1);
1979 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "HttpRequest does not contain a response message");
1986 /* {{{ proto HttpMessage HttpRequest::getRequestMessage()
1988 * Get sent HTTP message.
1990 * Returns an HttpMessage object representing the sent request.
1992 * If redirects were allowed and several responses were received, the data
1993 * references the last received response. Use HttpMessage::getParentMessage()
1994 * to access the data of previously sent requests within this request
1997 * Note that the internal request message is immutable, that means that the
1998 * request message received through HttpRequest::getRequestMessage() will
1999 * always look the same for the same request, regardless of any changes you
2000 * may have made to the returned object.
2002 * Throws HttpMalformedHeadersException, HttpEncodingException.
2004 PHP_METHOD(HttpRequest
, getRequestMessage
)
2008 if (return_value_used
) {
2010 getObject(http_request_object
, obj
);
2012 SET_EH_THROW_HTTP();
2013 if ((msg
= http_message_parse(PHPSTR_VAL(&obj
->request
->conv
.request
), PHPSTR_LEN(&obj
->request
->conv
.request
)))) {
2014 RETVAL_OBJVAL(http_message_object_new_ex(http_message_object_ce
, msg
, NULL
), 0);
2021 /* {{{ proto string HttpRequest::getRawRequestMessage()
2023 * Get sent HTTP message.
2025 * Returns an HttpMessage in a form of a string
2027 PHP_METHOD(HttpRequest
, getRawRequestMessage
)
2031 if (return_value_used
) {
2032 getObject(http_request_object
, obj
);
2034 RETURN_PHPSTR_DUP(&obj
->request
->conv
.request
);
2039 /* {{{ proto string HttpRequest::getRawResponseMessage()
2041 * Get the entire HTTP response.
2043 * Returns the complete web server response, including the headers in a form of a string.
2045 PHP_METHOD(HttpRequest
, getRawResponseMessage
)
2049 if (return_value_used
) {
2050 getObject(http_request_object
, obj
);
2052 RETURN_PHPSTR_DUP(&obj
->request
->conv
.response
);
2057 /* {{{ proto HttpMessage HttpRequest::getHistory()
2059 * Get all sent requests and received responses as an HttpMessage object.
2061 * If you want to record history, set the instance variable
2062 * HttpRequest::$recordHistory to TRUE.
2064 * Returns an HttpMessage object representing the complete request/response
2067 * The object references the last received response, use HttpMessage::getParentMessage()
2068 * to access the data of previously sent requests and received responses.
2070 * Throws HttpRuntimeException.
2072 PHP_METHOD(HttpRequest
, getHistory
)
2076 if (return_value_used
) {
2079 SET_EH_THROW_HTTP();
2080 hist
= GET_PROP(history
);
2081 if (Z_TYPE_P(hist
) == IS_OBJECT
) {
2082 RETVAL_OBJECT(hist
, 1);
2084 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "The history is empty");
2091 /* {{{ proto void HttpRequest::clearHistory()
2093 * Clear the history.
2095 PHP_METHOD(HttpRequest
, clearHistory
)
2100 MAKE_STD_ZVAL(hist
);
2102 SET_PROP(history
, hist
);
2103 zval_ptr_dtor(&hist
);
2108 /* {{{ proto HttpMessage HttpRequest::send()
2110 * Send the HTTP request.
2112 * Returns the received response as HttpMessage object.
2114 * NOTE: While an exception may be thrown, the transfer could have succeeded
2115 * at least partially, so you might want to check the return values of various
2116 * HttpRequest::getResponse*() methods.
2118 * Throws HttpRuntimeException, HttpRequestException,
2119 * HttpMalformedHeaderException, HttpEncodingException.
2124 * $r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET);
2125 * $r->setOptions(array('lastmodified' => filemtime('local.rss')));
2126 * $r->addQueryData(array('category' => 3));
2129 * if ($r->getResponseCode() == 200) {
2130 * file_put_contents('local.rss', $r->getResponseBody());
2132 * } catch (HttpException $ex) {
2141 * $r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
2142 * $r->setOptions(array('cookies' => array('lang' => 'de')));
2143 * $r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
2144 * $r->addPostFile('image', 'profile.jpg', 'image/jpeg');
2146 * echo $r->send()->getBody();
2147 * } catch (HttpException $ex) {
2153 PHP_METHOD(HttpRequest
, send
)
2155 getObject(http_request_object
, obj
);
2159 SET_EH_THROW_HTTP();
2164 http_error(HE_WARNING
, HTTP_E_RUNTIME
, "Cannot perform HttpRequest::send() while attached to an HttpRequestPool");
2165 } else if (SUCCESS
== http_request_object_requesthandler(obj
, getThis())) {
2166 http_request_exec(obj
->request
);
2167 if (SUCCESS
== http_request_object_responsehandler(obj
, getThis())) {
2168 RETVAL_OBJECT(GET_PROP(responseMessage
), 1);
2176 #endif /* ZEND_ENGINE_2 && HTTP_HAVE_CURL */
2183 * vim600: noet sw=4 ts=4 fdm=marker
2184 * vim<600: noet sw=4 ts=4