; the hashing algorithm with wich ETags are generated (MD5, SHA1, CRC32B)
; if ext/hash is available, this can be set to any hash algorithm ext/hash supports
; MD5 is the default and fallback algorithm
-http.etag_mode = "MD5"
+http.etag.mode = "MD5"
; allowed request methods
; by default PHP ignores unkown request methods
; PHP will exit with a response status of 405 and an Allow header
; if it encounters a request method not contained in the specified list
-;http.allowed_methods = "HEAD, GET, POST"
+;http.request.methods.allowed = "HEAD, GET, POST"
+
+; custom request methods
+;http.request.methods.custom = "KICK, BANN"
; log file for positive cache hits
-;http.cache_log =
+;http.log.cache =
; log file for redirects
-;http.redirect_log =
+;http.log.redirect =
; log file for requests with an unallowed request method
-;http.allowed_methods_log =
+;http.log.allowed_methods =
; composite log file (i.e. log all messages to this file)
-;http.composite_log =
+;http.log.composite =
; automatically deflate content if requested/supported by client
-;http.ob_deflate_auto = 1
-;http.ob_deflate_flags = HTTP_DEFLATE_LEVEL_DEF
+;http.send.deflate.start_auto = 1
+;http.send.deflate.start_flags = HTTP_DEFLATE_LEVEL_DEF
-; automatically inflate compressed content
-;http.ob_inflate_auto = 0
-;http.ob_inflate_flags =
+; automatically inflate sent content
+;http.send.inflate.start_auto = 0
+;http.send.inflate.start_flags =
#endif
PHP_INI_BEGIN()
- HTTP_PHP_INI_ENTRY("http.allowed_methods", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
- HTTP_PHP_INI_ENTRY("http.cache_log", "", PHP_INI_ALL, OnUpdateString, log.cache)
- HTTP_PHP_INI_ENTRY("http.redirect_log", "", PHP_INI_ALL, OnUpdateString, log.redirect)
- HTTP_PHP_INI_ENTRY("http.allowed_methods_log", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
- HTTP_PHP_INI_ENTRY("http.composite_log", "", PHP_INI_ALL, OnUpdateString, log.composite)
- HTTP_PHP_INI_ENTRY("http.etag_mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
+ HTTP_PHP_INI_ENTRY("http.etag.mode", "MD5", PHP_INI_ALL, OnUpdateString, etag.mode)
+ HTTP_PHP_INI_ENTRY("http.log.cache", "", PHP_INI_ALL, OnUpdateString, log.cache)
+ HTTP_PHP_INI_ENTRY("http.log.redirect", "", PHP_INI_ALL, OnUpdateString, log.redirect)
+ HTTP_PHP_INI_ENTRY("http.log.allowed_methods", "", PHP_INI_ALL, OnUpdateString, log.allowed_methods)
+ HTTP_PHP_INI_ENTRY("http.log.composite", "", PHP_INI_ALL, OnUpdateString, log.composite)
+ HTTP_PHP_INI_ENTRY("http.request.methods.allowed", "", PHP_INI_ALL, http_update_allowed_methods, request.methods.allowed)
+ HTTP_PHP_INI_ENTRY("http.request.methods.custom", "", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateString, request.methods.custom.ini)
+#ifdef HTTP_HAVE_ZLIB
+ HTTP_PHP_INI_ENTRY("http.send.inflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.inflate.start_auto)
+ HTTP_PHP_INI_ENTRY("http.send.inflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
+ HTTP_PHP_INI_ENTRY("http.send.deflate.start_auto", "0", PHP_INI_PERDIR|PHP_INI_SYSTEM, OnUpdateBool, send.deflate.start_auto)
+ HTTP_PHP_INI_ENTRY("http.send.deflate.start_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
+#endif
#ifdef ZEND_ENGINE_2
HTTP_PHP_INI_ENTRY("http.only_exceptions", "0", PHP_INI_ALL, OnUpdateBool, only_exceptions)
#endif
HTTP_PHP_INI_ENTRY("http.force_exit", "1", PHP_INI_ALL, OnUpdateBool, force_exit)
-#ifdef HTTP_HAVE_ZLIB
- HTTP_PHP_INI_ENTRY("http.ob_inflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.inflate.start_auto)
- HTTP_PHP_INI_ENTRY("http.ob_inflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.inflate.start_flags)
- HTTP_PHP_INI_ENTRY("http.ob_deflate_auto", "0", PHP_INI_PERDIR, OnUpdateBool, send.deflate.start_auto)
- HTTP_PHP_INI_ENTRY("http.ob_deflate_flags", "0", PHP_INI_ALL, OnUpdateLong, send.deflate.start_flags)
-#endif
PHP_INI_END()
/* }}} */
HTTP_LONG_CONSTANT("HTTP_SUPPORT_ENCODINGS", HTTP_SUPPORT_ENCODINGS);
HTTP_LONG_CONSTANT("HTTP_SUPPORT_SSLREQUESTS", HTTP_SUPPORT_SSLREQUESTS);
+ HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_COMMA", HTTP_PARAMS_ALLOW_COMMA);
+ HTTP_LONG_CONSTANT("HTTP_PARAMS_ALLOW_FAILURE", HTTP_PARAMS_ALLOW_FAILURE);
+ HTTP_LONG_CONSTANT("HTTP_PARAMS_RAISE_ERROR", HTTP_PARAMS_RAISE_ERROR);
+ HTTP_LONG_CONSTANT("HTTP_PARAMS_DEFAULT", HTTP_PARAMS_DEFAULT);
+
return SUCCESS;
}
/* }}} */
/* {{{ STATUS http_parse_params(const char *, HashTable *) */
-PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int allow_comma_sep, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
+PHP_HTTP_API STATUS _http_parse_params_ex(const char *param, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC)
{
#define ST_QUOTE 1
#define ST_VALUE 2
st == ST_ASSIGN ? "ASSIGN" :
st == ST_ADD ? "ADD":
"HUH?"
- ), *c, tk, tv
+ ), *c?*c:'0', tk, tv
);
STR_FREE(tk); STR_FREE(tv);
#endif
+ continued:
switch (st) {
case ST_QUOTE:
quote:
case '\0':
goto add;
break;
-
+ case ',':
+ if (flags & HTTP_PARAMS_ALLOW_COMMA) {
+ goto add;
+ }
default:
if (!val) {
val = c;
case ST_KEY:
switch (*c) {
case ',':
- if (allow_comma_sep) {
+ if (flags & HTTP_PARAMS_ALLOW_COMMA) {
goto allow_comma;
}
case '\r':
case '\0':
allow_comma:
if (key) {
- keylen = c - key;
+ keylen = c-- - key;
st = ST_ADD;
}
break;
case ST_ASSIGN:
if (*c == '=') {
st = ST_VALUE;
- } else if (!*c || *c == ';') {
+ } else if (!*c || *c == ';' || ((flags & HTTP_PARAMS_ALLOW_COMMA) && *c == ',')) {
st = ST_ADD;
} else if (*c != ' ') {
goto failure;
keylen = vallen = 0;
break;
}
-
if (*c) {
++c;
} else if (st == ST_ADD) {
return SUCCESS;
failure:
- http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
+ if (flags & HTTP_PARAMS_RAISE_ERROR) {
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Unexpected character (%c) at pos %tu of %zu", *c, c-s, strlen(s));
+ }
+ if (flags & HTTP_PARAMS_ALLOW_FAILURE) {
+ --c;
+ st = ST_ADD;
+ goto continued;
+ }
efree(s);
return FAILURE;
}
arg.flags = flags;
arg.allowed_extras = allowed_extras;
- if (SUCCESS != http_parse_params_ex(string, 0, http_parse_cookie_callback, &arg)) {
+ if (SUCCESS != http_parse_params_ex(string, HTTP_PARAMS_RAISE_ERROR, http_parse_cookie_callback, &arg)) {
if (free_list) {
http_cookie_list_free(&list);
} else {
}
}
-/* {{{ proto object http_parse_params(string param)
+/* {{{ proto object http_parse_params(string param[, int flags = HTTP_PARAMS_DEFAULT])
*
* Parse parameter list.
*/
char *param;
int param_len;
zval *params;
+ long flags = HTTP_PARAMS_DEFAULT;
- if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", ¶m, ¶m_len)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", ¶m, ¶m_len, &flags)) {
RETURN_FALSE;
}
params = ecalloc(1, sizeof(zval));
array_init(params);
- if (SUCCESS != http_parse_params(param, Z_ARRVAL_P(params))) {
+ if (SUCCESS != http_parse_params(param, flags, Z_ARRVAL_P(params))) {
zval_dtor(params);
FREE_ZVAL(params);
RETURN_FALSE;
{
HTTP_G->request.methods.custom.entries = ecalloc(1, sizeof(http_request_method_entry *));
+ if (HTTP_G->request.methods.custom.ini && *HTTP_G->request.methods.custom.ini) {
+ HashPosition pos;
+ HashTable methods;
+ zval **data;
+
+ zend_hash_init(&methods, 0, NULL, ZVAL_PTR_DTOR, 0);
+ http_parse_params(HTTP_G->request.methods.custom.ini, &methods);
+ FOREACH_HASH_VAL(pos, &methods, data) {
+ if (Z_TYPE_PP(data) == IS_STRING) {
+ http_request_method_register(Z_STRVAL_PP(data), Z_STRLEN_PP(data));
+ }
+ }
+ zend_hash_destroy(&methods);
+ }
return SUCCESS;
}
HTTP_BEGIN_ARGS(parseParams, 1)
HTTP_ARG_VAL(param_string, 0)
+ HTTP_ARG_VAL(flags, 0)
HTTP_END_ARGS;
HTTP_BEGIN_ARGS(chunkedDecode, 1)
It provides powerful request functionality, if built with CURL
support. Parallel requests are available for PHP-5 and greater.
-
-PHP-5 classes:
-HttpUtil, HttpMessage, HttpRequest, HttpRequestPool,
-HttpDeflateStream, HttpInflateStream, HttpQueryString
-
-PHP-5.1 classes:
-HttpResponse
]]></description>
<lead>
<name>Michael Wallner</name>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
++ Added HttpRequest::enableCookies() and HttpRequest::resetCookies([bool session_only=FALSE])
++ Added optional flags argument to http_parse_params()
++ Added HTTP_PARAMS_ALLOW_COMMA, HTTP_PARAMS_ALLOW_FAILURE, HTTP_PARAMS_RAISE_ERROR constants
* Fixed http_build_url("./path") if REQUEST_URI is empty
+* Fixed http_parse_params("foo;bar") returning "foo" and "ar"
+* Fixed return value of http_parse_params() Object{"params"=>Array("value", Array("name"=>"value"), ...)}
+* Fixed HttpMessage::setRequestMethod() errenously issuing a warning about an unknown request method
]]></notes>
<contents>
<dir name="/">
<file role="test" name="HttpRequest_007.phpt"/>
<file role="test" name="HttpRequest_008.phpt"/>
<file role="test" name="HttpRequest_009.phpt"/>
+ <file role="test" name="HttpRequest_010.phpt"/>
<file role="test" name="HttpRequestPool_001.phpt"/>
<file role="test" name="HttpRequestPool_002.phpt"/>
<file role="test" name="HttpRequestPool_003.phpt"/>
<file role="test" name="parse_message_003.phpt"/>
<file role="test" name="parse_message_004.phpt"/>
<file role="test" name="parse_message_005.phpt"/>
+ <file role="test" name="parse_params_001.phpt"/>
<file role="test" name="redirect_001.phpt"/>
<file role="test" name="redirect_001_logging.phpt"/>
<file role="test" name="redirect_002.phpt"/>
struct _http_globals_request_methods {
char *allowed;
struct _http_globals_request_methods_custom {
+ char *ini;
int count;
void *entries;
} custom;
#define HTTP_SUPPORT_ENCODINGS 0x08L
#define HTTP_SUPPORT_SSLREQUESTS 0x20L
+#define HTTP_PARAMS_ALLOW_COMMA 0x01
+#define HTTP_PARAMS_ALLOW_FAILURE 0x02
+#define HTTP_PARAMS_RAISE_ERROR 0x04
+#define HTTP_PARAMS_DEFAULT (HTTP_PARAMS_ALLOW_COMMA|HTTP_PARAMS_ALLOW_FAILURE|HTTP_PARAMS_RAISE_ERROR)
+
extern PHP_MINIT_FUNCTION(http_support);
#define http_support(f) _http_support(f)
#define http_parse_params_default_callback _http_parse_params_default_callback
PHP_HTTP_API void _http_parse_params_default_callback(void *ht, const char *key, int keylen, const char *val, int vallen TSRMLS_DC);
-#define http_parse_params(s, ht) _http_parse_params_ex((s), 1, _http_parse_params_default_callback, (ht) TSRMLS_CC)
-#define http_parse_params_ex(s, comma, cb, a) _http_parse_params_ex((s), (comma), (cb), (a) TSRMLS_CC)
-PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int alloc_comma_sep, http_parse_params_callback cb, void *cb_arg TSRMLS_DC);
+#define http_parse_params(s, f, ht) _http_parse_params_ex((s), (f), _http_parse_params_default_callback, (ht) TSRMLS_CC)
+#define http_parse_params_ex(s, f, cb, a) _http_parse_params_ex((s), (f), (cb), (a) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_parse_params_ex(const char *params, int flags, http_parse_params_callback cb, void *cb_arg TSRMLS_DC);
#define http_locate_body _http_locate_body