+/* {{{ */
+PHP_MINIT_FUNCTION(http_send)
+{
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT", HTTP_REDIRECT);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_PERM", HTTP_REDIRECT_PERM);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_FOUND", HTTP_REDIRECT_FOUND);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_POST", HTTP_REDIRECT_POST);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_PROXY", HTTP_REDIRECT_PROXY);
+ HTTP_LONG_CONSTANT("HTTP_REDIRECT_TEMP", HTTP_REDIRECT_TEMP);
+
+ return SUCCESS;
+}
+/* }}} */
+
+/* {{{ http_find_header */
+typedef struct {
+ const char *h;
+ size_t l;
+} http_response_header_t;
+
+static int http_find_header(void *data, void *arg)
+{
+ http_response_header_t *h = arg;
+ sapi_header_struct *s = data;
+
+ return (!strncasecmp(s->header, h->h, h->l)) && s->header[h->l] == ':';
+}
+/* }}} */
+
+/* {{{ void http_hide_header(char *) */
+PHP_HTTP_API void _http_hide_header_ex(const char *name, size_t name_len TSRMLS_DC)
+{
+ http_response_header_t h = {name, name_len};
+ zend_llist_del_element(&SG(sapi_headers).headers, (void *) &h, http_find_header);
+}
+/* }}} */
+
+/* {{{ void http_send_header_zval(char*, zval **, zend_bool) */
+PHP_HTTP_API void _http_send_header_zval_ex(const char *name, size_t name_len, zval **val, zend_bool replace TSRMLS_DC)
+{
+ if (!val || !*val || Z_TYPE_PP(val) == IS_NULL || (Z_TYPE_PP(val) == IS_STRING && !Z_STRLEN_PP(val))) {
+ http_hide_header_ex(name, name_len);
+ } else if (Z_TYPE_PP(val) == IS_ARRAY || Z_TYPE_PP(val) == IS_OBJECT) {
+ zend_bool first = replace;
+ zval **data_ptr;
+ HashPosition pos;
+
+ FOREACH_HASH_VAL(pos, HASH_OF(*val), data_ptr) {
+ zval *data = http_zsep(IS_STRING, *data_ptr);
+
+ http_send_header_ex(name, name_len, Z_STRVAL_P(data), Z_STRLEN_P(data), first, NULL);
+ zval_ptr_dtor(&data);
+ first = 0;
+ }
+ } else {
+ zval *data = http_zsep(IS_STRING, *val);
+
+ http_send_header_ex(name, name_len, Z_STRVAL_P(data), Z_STRLEN_P(data), replace, NULL);
+ zval_ptr_dtor(&data);
+ }
+}
+/* }}} */