+ char *name = NULL;
+ int name_len = 0;
+ zval *headers, **header;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &name, &name_len)) {
+ RETURN_FALSE;
+ }
+
+ headers = GET_STATIC_PROP(headers);
+ if (Z_TYPE_P(headers) != IS_ARRAY) {
+ convert_to_array(headers);
+ }
+
+ if (!name || !name_len) {
+ array_init(return_value);
+ array_copy(headers, return_value);
+ } else if (SUCCESS == zend_hash_find(Z_ARRVAL_P(headers), name, name_len + 1, (void **) &header)) {
+ RETURN_ZVAL(*header, ZVAL_PTR_DTOR, 1);
+ } else {
+ RETURN_NULL();
+ }
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setCache(bool cache)
+ *
+ * Whether it sould be attempted to cache the entitity.
+ * This will result in necessary caching headers and checks of clients
+ * "If-Modified-Since" and "If-None-Match" headers. If one of those headers
+ * matches a "304 Not Modified" status code will be issued.
+ *
+ * NOTE: If you're using sessions, be shure that you set session.cache_limiter
+ * to something more appropriate than "no-cache"!
+ */
+PHP_METHOD(HttpResponse, setCache)
+{
+ zend_bool do_cache = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_cache)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_SUCCESS(UPD_STATIC_PROP(bool, cache, do_cache));
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::getCache()
+ *
+ * Get current caching setting.
+ */
+PHP_METHOD(HttpResponse, getCache)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(cache)));
+ }
+}
+/* }}}*/
+
+/* {{{ proto static bool HttpResponse::setGzip(bool gzip)
+ *
+ * Enable on-thy-fly gzipping of the sent entity.
+ */
+PHP_METHOD(HttpResponse, setGzip)
+{
+ zend_bool do_gzip = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "b", &do_gzip)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_SUCCESS(UPD_STATIC_PROP(bool, gzip, do_gzip));
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::getGzip()
+ *
+ * Get current gzipping setting.
+ */
+PHP_METHOD(HttpResponse, getGzip)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(gzip)));
+ }
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setCacheControl(string control[, long max_age = 0])
+ *
+ * Set a custom cache-control header, usually being "private" or "public";
+ * The max_age parameter controls how long the cache entry is valid on the client side.
+ */
+PHP_METHOD(HttpResponse, setCacheControl)
+{
+ char *ccontrol, *cctl;
+ int cc_len;
+ long max_age = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ccontrol, &cc_len, &max_age)) {
+ RETURN_FALSE;
+ }
+
+ if (strcmp(ccontrol, "public") && strcmp(ccontrol, "private") && strcmp(ccontrol, "no-cache")) {
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol);
+ RETURN_FALSE;
+ } else {
+ spprintf(&cctl, 0, "%s, must-revalidate, max_age=%ld", ccontrol, max_age);
+ RETVAL_SUCCESS(UPD_STATIC_PROP(string, cacheControl, cctl));
+ efree(cctl);
+ }
+}
+/* }}} */
+
+/* {{{ proto static string HttpResponse::getCacheControl()
+ *
+ * Get current Cache-Control header setting.
+ */
+PHP_METHOD(HttpResponse, getCacheControl)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ zval *ccontrol = GET_STATIC_PROP(cacheControl);
+ RETURN_STRINGL(Z_STRVAL_P(ccontrol), Z_STRLEN_P(ccontrol), 1);
+ }
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setContentType(string content_type)
+ *
+ * Set the content-type of the sent entity.
+ */
+PHP_METHOD(HttpResponse, setContentType)
+{
+ char *ctype;
+ int ctype_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &ctype, &ctype_len)) {
+ RETURN_FALSE;
+ }
+
+ if (!strchr(ctype, '/')) {
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype);
+ RETURN_FALSE;
+ }
+
+ RETURN_SUCCESS(UPD_STATIC_PROP(string, contentType, ctype));
+}
+/* }}} */
+
+/* {{{ proto static string HttpResponse::getContentType()
+ *
+ * Get current Content-Type header setting.
+ */
+PHP_METHOD(HttpResponse, getContentType)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ zval *ctype = GET_STATIC_PROP(contentType);
+ RETURN_STRINGL(Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ }
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
+ *
+ * Set the Content-Disposition of the sent entity. This setting aims to suggest
+ * the receiveing user agent how to handle the sent entity; usually the client
+ * will show the user a "Save As..." popup.
+ */
+PHP_METHOD(HttpResponse, setContentDisposition)
+{
+ char *file, *cd;
+ int file_len;
+ zend_bool send_inline = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", &file, &file_len, &send_inline)) {
+ RETURN_FALSE;
+ }
+
+ spprintf(&cd, 0, "%s; filename=\"%s\"", send_inline ? "inline" : "attachment", file);
+ RETVAL_SUCCESS(UPD_STATIC_PROP(string, contentDisposition, cd));
+ efree(cd);
+}
+/* }}} */
+
+/* {{{ proto static string HttpResponse::getContentDisposition()
+ *
+ * Get current Content-Disposition setting.
+ */
+PHP_METHOD(HttpResponse, getContentDisposition)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ zval *cd = GET_STATIC_PROP(contentDisposition);
+ RETURN_STRINGL(Z_STRVAL_P(cd), Z_STRLEN_P(cd), 1);
+ }
+}
+/* }}} */
+
+/* {{{ proto static bool HttpResponse::setETag(string etag)
+ *
+ * Set a custom ETag. Use this only if you know what you're doing.
+ */
+PHP_METHOD(HttpResponse, setETag)
+{
+ char *etag;
+ int etag_len;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &etag, &etag_len)) {
+ RETURN_FALSE;
+ }
+
+ RETURN_SUCCESS(UPD_STATIC_PROP(string, eTag, etag));
+}
+/* }}} */
+
+/* {{{ proto static string HttpResponse::getETag()
+ *
+ * Get calculated or previously set custom ETag.
+ */
+PHP_METHOD(HttpResponse, getETag)
+{
+ NO_ARGS;
+
+ IF_RETVAL_USED {
+ zval *etag = GET_STATIC_PROP(eTag);
+ RETURN_STRINGL(Z_STRVAL_P(etag), Z_STRLEN_P(etag), 1);
+ }
+}
+/* }}} */