From 33601b5f7d0b26b1e7f95ca44f349426594fbece Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 6 Apr 2006 13:50:32 +0000 Subject: [PATCH] - added missing http_request() function stub --- http.c | 1 + http_functions.c | 43 +++++++++++++++++++++++++++++++++++++++++++ package2.xml | 1 + php_http.h | 1 + 4 files changed, 46 insertions(+) diff --git a/http.c b/http.c index d514b38..807910a 100644 --- a/http.c +++ b/http.c @@ -105,6 +105,7 @@ zend_function_entry http_functions[] = { PHP_FE(http_put_data, http_arg_pass_ref_4) PHP_FE(http_put_file, http_arg_pass_ref_4) PHP_FE(http_put_stream, http_arg_pass_ref_4) + PHP_FE(http_request, http_arg_pass_ref_5) #endif PHP_FE(http_request_method_register, NULL) PHP_FE(http_request_method_unregister, NULL) diff --git a/http_functions.c b/http_functions.c index 2cd1dfe..89a8c61 100644 --- a/http_functions.c +++ b/http_functions.c @@ -1624,6 +1624,49 @@ PHP_FUNCTION(http_put_data) http_request_dtor(&request); } /* }}} */ + +/* {{{ proto string http_request(int method, string url[, string body[, array options[, array &info]]]) + * + * Performs a custom HTTP request on the supplied url. + * + * Expects the first parameter to be an integer specifying the request method to use. + * Accepts an optional third string parameter containing the raw request body. + * See http_get() for a full list of available options. + * + * Returns the HTTP response(s) as string on success, or FALSE on failure. + */ +PHP_FUNCTION(http_request) +{ + long meth; + char *URL, *data = NULL; + int URL_len, data_len = 0; + zval *options = NULL, *info = NULL; + http_request_body body; + http_request request; + + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls|sa/!z", &meth, &URL, &URL_len, &data, &data_len, &options, &info)) { + RETURN_FALSE; + } + + if (info) { + zval_dtor(info); + array_init(info); + } + + RETVAL_FALSE; + + http_request_init_ex(&request, NULL, meth, URL); + request.body = http_request_body_init_ex(&body, HTTP_REQUEST_BODY_CSTRING, data, data_len, 0); + if (SUCCESS == http_request_prepare(&request, options?Z_ARRVAL_P(options):NULL)) { + http_request_exec(&request); + if (info) { + http_request_info(&request, Z_ARRVAL_P(info)); + } + RETVAL_RESPONSE_OR_BODY(request); + } + http_request_dtor(&request); +} +/* }}} */ #endif /* HTTP_HAVE_CURL */ /* }}} HAVE_CURL */ diff --git a/package2.xml b/package2.xml index 892f1c8..1a2e495 100644 --- a/package2.xml +++ b/package2.xml @@ -46,6 +46,7 @@ HttpResponse BSD, revised prepend($HttpMessage) causing infinite recursion * Fixed internal http_parse_headers() always returning success diff --git a/php_http.h b/php_http.h index 32ce1e3..6ff5418 100644 --- a/php_http.h +++ b/php_http.h @@ -181,6 +181,7 @@ PHP_FUNCTION(http_post_fields); PHP_FUNCTION(http_put_data); PHP_FUNCTION(http_put_file); PHP_FUNCTION(http_put_stream); +PHP_FUNCTION(http_request); #endif /* HTTP_HAVE_CURL */ PHP_FUNCTION(http_request_method_register); PHP_FUNCTION(http_request_method_unregister); -- 2.30.2