just use the flag for the data format you want to generate:
HTTP_DEFLATE_TYPE_GZIP, HTTP_DEFLATE_TYPE_ZLIB or HTTP_DEFLATE_TYPE_RAW.
-Windows:
- There's no HttpUtil alias for http_build_query() due to missing export.
-
Internals:
- there's a memleak with sizeof(zval) for each thrown exception,
which ends up in HttpRequestPoolExcepiont::$exceptionStack, in
PHP_FE(http_test, NULL)
PHP_FE(http_date, NULL)
PHP_FE(http_build_url, http_arg_pass_ref_4)
+ PHP_FE(http_build_str, NULL)
+#ifndef ZEND_ENGINE_2
+ PHP_FALIAS(http_build_query, http_build_str)
+#endif
PHP_FE(http_negotiate_language, http_arg_pass_ref_2)
PHP_FE(http_negotiate_charset, http_arg_pass_ref_2)
PHP_FE(http_negotiate_content_type, http_arg_pass_ref_2)
PHP_FE(http_request_method_unregister, NULL)
PHP_FE(http_request_method_exists, NULL)
PHP_FE(http_request_method_name, NULL)
-#ifndef ZEND_ENGINE_2
- PHP_FE(http_build_query, NULL)
-#endif
PHP_FE(ob_etaghandler, NULL)
#ifdef HTTP_HAVE_ZLIB
PHP_FE(http_deflate, NULL)
}
/* }}} */
+/* {{{ proto string http_build_str(array query [, string prefix[, string arg_separator]])
+ *
+ * Opponent to parse_str().
+ */
+PHP_FUNCTION(http_build_str)
+{
+ zval *formdata;
+ char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output");
+ int prefix_len = 0, arg_sep_len = strlen(arg_sep);
+ phpstr formstr;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
+ RETURN_FALSE;
+ }
+
+ if (!arg_sep_len) {
+ arg_sep = HTTP_URL_ARGSEP;
+ arg_sep_len = lenof(HTTP_URL_ARGSEP);
+ }
+
+ phpstr_init(&formstr);
+ if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), &formstr, arg_sep, arg_sep_len, prefix, prefix_len)) {
+ RETURN_FALSE;
+ }
+
+ if (!formstr.used) {
+ phpstr_dtor(&formstr);
+ RETURN_NULL();
+ }
+
+ RETURN_PHPSTR_VAL(&formstr);
+}
+/* }}} */
+
#define HTTP_DO_NEGOTIATE(type, supported, rs_array) \
{ \
HashTable *result; \
}
/* }}} */
-/* {{{ Sara Golemons http_build_query() */
-#ifndef ZEND_ENGINE_2
-
-/* {{{ proto string http_build_query(mixed formdata [, string prefix[, string arg_separator]])
- Generates a form-encoded query string from an associative array or object. */
-PHP_FUNCTION(http_build_query)
-{
- zval *formdata;
- char *prefix = NULL, *arg_sep = INI_STR("arg_separator.output");
- int prefix_len = 0, arg_sep_len = strlen(arg_sep);
- phpstr *formstr;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|ss", &formdata, &prefix, &prefix_len, &arg_sep, &arg_sep_len) != SUCCESS) {
- RETURN_FALSE;
- }
-
- if (!arg_sep_len) {
- arg_sep = HTTP_URL_ARGSEP;
- arg_sep_len = lenof(HTTP_URL_ARGSEP);
- }
-
- formstr = phpstr_new();
- if (SUCCESS != http_urlencode_hash_recursive(HASH_OF(formdata), formstr, arg_sep, arg_sep_len, prefix, prefix_len)) {
- phpstr_free(&formstr);
- RETURN_FALSE;
- }
-
- if (!formstr->used) {
- phpstr_free(&formstr);
- RETURN_NULL();
- }
-
- RETURN_PHPSTR_PTR(formstr);
-}
-/* }}} */
-#endif /* !ZEND_ENGINE_2 */
-/* }}} */
-
/* {{{ */
#ifdef HTTP_HAVE_ZLIB
HTTP_ARG_VAL(timestamp, 0)
HTTP_END_ARGS;
-#ifndef PHP_WIN32
HTTP_BEGIN_ARGS(buildQuery, 1)
HTTP_ARG_VAL(query, 0)
+ HTTP_ARG_VAL(prefix, 0)
+ HTTP_ARG_VAL(arg_sep, 0)
HTTP_END_ARGS;
-#endif
HTTP_BEGIN_ARGS(buildUrl, 1)
HTTP_ARG_VAL(url, 0)
zend_function_entry http_util_object_fe[] = {
HTTP_UTIL_ALIAS(date, http_date)
HTTP_UTIL_ALIAS(buildUrl, http_build_url)
-#ifndef PHP_WIN32
- HTTP_UTIL_ALIAS(buildQuery, http_build_query)
-#endif
+ HTTP_UTIL_ALIAS(buildQuery, http_build_str)
HTTP_UTIL_ALIAS(negotiateLanguage, http_negotiate_language)
HTTP_UTIL_ALIAS(negotiateCharset, http_negotiate_charset)
HTTP_UTIL_ALIAS(negotiateContentType, http_negotiate_content_type)
#ifndef PHP_EXT_HTTP_H
#define PHP_EXT_HTTP_H
-#define PHP_EXT_HTTP_VERSION "0.22.0"
+#define PHP_EXT_HTTP_VERSION "0.23.0dev"
#ifdef HAVE_CONFIG_H
# include "config.h"
PHP_FUNCTION(http_test);
PHP_FUNCTION(http_date);
PHP_FUNCTION(http_build_url);
+PHP_FUNCTION(http_build_str);
PHP_FUNCTION(http_negotiate_language);
PHP_FUNCTION(http_negotiate_charset);
PHP_FUNCTION(http_negotiate_content_type);
PHP_FUNCTION(http_request_method_unregister);
PHP_FUNCTION(http_request_method_exists);
PHP_FUNCTION(http_request_method_name);
-#ifndef ZEND_ENGINE_2
-PHP_FUNCTION(http_build_query);
-#endif /* ZEND_ENGINE_2 */
PHP_FUNCTION(ob_etaghandler);
#ifdef HTTP_HAVE_ZLIB
PHP_FUNCTION(http_deflate);
PHP_METHOD(HttpUtil, date);
PHP_METHOD(HttpUtil, buildUrl);
-#ifndef PHP_WIN32
PHP_METHOD(HttpUtil, buildQuery);
-#endif
PHP_METHOD(HttpUtil, negotiateLanguage);
PHP_METHOD(HttpUtil, negotiateCharset);
PHP_METHOD(HttpUtil, negotiateContentType);
--- /dev/null
+--TEST--
+http_build_str
+--SKIPIF--
+<?php
+include 'skip.inc';
+?>
+--FILE--
+<?php
+echo "-TEST\n";
+
+parse_str($s = "a=b", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+parse_str($s = "a=b&c[0]=1", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+parse_str($s = "a=b&c[0]=1&d[e]=f", $q);
+var_dump($s === http_build_str($q, null, "&"));
+
+var_dump("foo[0]=1&foo[1]=2&foo[2][0]=3" === http_build_str(array(1,2,array(3)), "foo", "&"));
+
+echo "Done\n";
+?>
+--EXPECTF--
+%sTEST
+bool(true)
+bool(true)
+bool(true)
+bool(true)
+Done