PHP_FE(http_split_response, NULL)
PHP_FE(http_parse_headers, NULL)
PHP_FE(http_get_request_headers, NULL)
+ PHP_FE(http_match_request_header, NULL)
#ifdef HTTP_HAVE_CURL
PHP_FE(http_get, http_request_info_ref_3)
PHP_FE(http_head, http_request_info_ref_3)
/* {{{ proto array http_get_request_headers(void)
*
+ * Get a list of incoming HTTP headers.
*/
PHP_FUNCTION(http_get_request_headers)
{
}
/* }}} */
+/* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
+ *
+ * Match an incoming HTTP header.
+ */
+PHP_FUNCTION(http_match_request_header)
+{
+ char *header, *value;
+ int header_len, value_len;
+ zend_bool match_case = 0, result = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|b", &header, &header_len, &value, &value_len, &match_case)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_BOOL(http_match_request_header_ex(header, value, match_case));
+}
+/* }}} */
+
/* {{{ HAVE_CURL */
#ifdef HTTP_HAVE_CURL
} else {
RETVAL_FALSE;
}
- http_request_body_dtor(&body);
}
/* }}} */
}
/* }}} */
+/* {{{ zend_bool http_match_request_header(char *, char *) */
+PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC)
+{
+ char *name, *key = NULL;
+ ulong idx;
+ zend_bool result = 0;
+ HashTable headers;
+
+ name = pretty_key(estrdup(header), strlen(header), 1, 1);
+ zend_hash_init(&headers, 0, NULL, ZVAL_PTR_DTOR, 0);
+ http_get_request_headers_ex(&headers, 1);
+
+ FOREACH_HASH_KEY(&headers, key, idx) {
+ if (key && (!strcmp(key, name))) {
+ zval **data;
+
+ if (SUCCESS == zend_hash_get_current_data(&headers, (void **) &data)) {
+ result = (match_case ? strcmp(Z_STRVAL_PP(data), value) : strcasecmp(Z_STRVAL_PP(data), value)) ? 0 : 1;
+ }
+ break;
+ }
+ }
+
+ zend_hash_destroy(&headers);
+ efree(name);
+
+ return result;
+}
+/* }}} */
+
/*
* Local variables:
PHP_FUNCTION(http_split_response);
PHP_FUNCTION(http_parse_headers);
PHP_FUNCTION(http_get_request_headers);
+PHP_FUNCTION(http_match_request_header);
#ifdef HTTP_HAVE_CURL
PHP_FUNCTION(http_get);
PHP_FUNCTION(http_head);
PHP_HTTP_API STATUS _http_parse_cookie(const char *cookie, HashTable *values TSRMLS_DC);
#define http_get_request_headers(h) _http_get_request_headers_ex(Z_ARRVAL_P(h), 1 TSRMLS_CC)
-#define http_get_request_headers_ex(h, p) _http_get_request_headers_ex((h), (s) TSRMLS_CC)
+#define http_get_request_headers_ex(h, p) _http_get_request_headers_ex((h), (p) TSRMLS_CC)
PHP_HTTP_API void _http_get_request_headers_ex(HashTable *headers, zend_bool prettify TSRMLS_DC);
#define http_negotiate_language(zsupported, def) http_negotiate_language_ex(Z_ARRVAL_P(zsupported), (def))
#define http_get_request_ranges(r, l) _http_get_request_ranges((r), (l) TSRMLS_CC)
PHP_HTTP_API http_range_status _http_get_request_ranges(HashTable *ranges, size_t length TSRMLS_DC);
+#define http_match_request_header(h, v) http_match_request_header_ex((h), (v), 0)
+#define http_match_request_header_ex(h, v, c) _http_match_request_header_ex((h), (v), (c) TSRMLS_CC)
+PHP_HTTP_API zend_bool _http_match_request_header_ex(const char *header, const char *value, zend_bool match_case TSRMLS_DC);
+
#endif
/*