+/* {{{ proto static bool HttpResponse::setHeader(string name, mixed value[, bool replace = true])
+ *
+ * Send an HTTP header.
+ *
+ * Expects a string parameter containing the name of the header and a mixed
+ * parameter containing the value of the header, which will be converted to
+ * a string. Additionally accepts an optional boolean parameter, which
+ * specifies whether an existing header should be replaced. If the second
+ * parameter is unset no header with this name will be sent.
+ *
+ * Returns TRUE on success, or FALSE on failure.
+ *
+ * Throws HttpHeaderException if http.only_exceptions is TRUE.
+ */
+PHP_METHOD(HttpResponse, setHeader)
+{
+ zend_bool replace = 1;
+ char *name;
+ int name_len = 0;
+ zval *value = NULL, *orig = NULL;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz/!|b", &name, &name_len, &value, &replace)) {
+ RETURN_FALSE;
+ }
+ if (SG(headers_sent)) {
+ http_error(HE_WARNING, HTTP_E_HEADER, "Cannot add another header when headers have already been sent");
+ RETURN_FALSE;
+ }
+ if (!name_len) {
+ http_error(HE_WARNING, HTTP_E_HEADER, "Cannot send anonymous headers");
+ RETURN_FALSE;
+ }
+
+ /* delete header if value == null */
+ if (!value || Z_TYPE_P(value) == IS_NULL) {
+ RETURN_SUCCESS(http_send_header_ex(name, name_len, "", 0, replace, NULL));
+ }
+ /* send multiple header if replace is false and value is an array */
+ if (!replace && Z_TYPE_P(value) == IS_ARRAY) {
+ zval **data;
+ HashPosition pos;
+
+ FOREACH_VAL(pos, value, data) {
+ zval *orig = *data;
+
+ convert_to_string_ex(data);
+ if (SUCCESS != http_send_header_ex(name, name_len, Z_STRVAL_PP(data), Z_STRLEN_PP(data), 0, NULL)) {
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
+ RETURN_FALSE;
+ }
+ if (orig != *data) {
+ zval_ptr_dtor(data);
+ }
+ }
+ RETURN_TRUE;
+ }
+ /* send standard header */
+ orig = value;
+ convert_to_string_ex(&value);
+ RETVAL_SUCCESS(http_send_header_ex(name, name_len, Z_STRVAL_P(value), Z_STRLEN_P(value), replace, NULL));
+ if (orig != value) {
+ zval_ptr_dtor(&value);
+ }
+}
+/* }}} */
+
+/* {{{ proto static mixed HttpResponse::getHeader([string name])
+ *
+ * Get header(s) about to be sent.
+ *
+ * Accepts a string as optional parameter which specifies the name of the
+ * header to read. If the parameter is empty or omitted, an associative array
+ * with all headers will be returned.
+ *
+ * NOTE: In Apache2 this only works for PHP-5.1.3 and greater.
+ *
+ * Returns either a string containing the value of the header matching name,
+ * FALSE on failure, or an associative array with all headers.
+ */
+PHP_METHOD(HttpResponse, getHeader)
+{
+ char *name = NULL;
+ int name_len = 0;
+ phpstr headers;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len)) {
+ RETURN_FALSE;
+ }
+
+ phpstr_init(&headers);
+ zend_llist_apply_with_argument(&SG(sapi_headers).headers, http_grab_response_headers, &headers TSRMLS_CC);
+ phpstr_fix(&headers);
+
+ if (name && name_len) {
+ zval **header;
+ HashTable headers_ht;
+
+ zend_hash_init(&headers_ht, sizeof(zval *), NULL, ZVAL_PTR_DTOR, 0);
+ if ( (SUCCESS == http_parse_headers_ex(PHPSTR_VAL(&headers), &headers_ht, 1)) &&
+ (SUCCESS == zend_hash_find(&headers_ht, name, name_len + 1, (void **) &header))) {
+ RETVAL_ZVAL(*header, 1, 0);
+ } else {
+ RETVAL_NULL();
+ }
+ zend_hash_destroy(&headers_ht);
+ } else {
+ array_init(return_value);
+ http_parse_headers_ex(PHPSTR_VAL(&headers), Z_ARRVAL_P(return_value), 1);
+ }
+
+ phpstr_dtor(&headers);
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setCache(bool cache)