+ zval *ctype = convert_to_type_ex(IS_STRING, GET_STATIC_PROP(contentType));
+
+ RETURN_ZVAL(ctype, 1, 0);
+ }
+}
+/* }}} */
+
+/* {{{ proto static string HttpResponse::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])
+ *
+ * Attempts to guess the content type of supplied payload through libmagic.
+ * If the attempt is successful, the guessed content type will automatically
+ * be set as response content type.
+ *
+ * Expects a string parameter specifying the magic.mime database to use.
+ * Additionally accepts an optional int parameter, being flags for libmagic.
+ *
+ * Returns the guessed content type on success, or FALSE on failure.
+ *
+ * Throws HttpRuntimeException, HttpInvalidParamException
+ * if http.only_exceptions is TRUE.
+ */
+PHP_METHOD(HttpResponse, guessContentType)
+{
+ char *magic_file, *ct = NULL;
+ int magic_file_len;
+ long magic_mode = 0;
+
+ RETVAL_FALSE;
+
+#ifdef HTTP_HAVE_MAGIC
+ magic_mode = MAGIC_MIME;
+
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
+ switch (Z_LVAL_P(GET_STATIC_PROP(mode))) {
+ case SEND_DATA:
+ {
+ zval *data = GET_STATIC_PROP(data);
+ ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(data), Z_STRLEN_P(data), SEND_DATA);
+ }
+ break;
+
+ case SEND_RSRC:
+ {
+ php_stream *s;
+ zval *z = GET_STATIC_PROP(stream);
+ z->type = IS_RESOURCE;
+ php_stream_from_zval(s, &z);
+ ct = http_guess_content_type(magic_file, magic_mode, s, 0, SEND_RSRC);
+ }
+ break;
+
+ default:
+ ct = http_guess_content_type(magic_file, magic_mode, Z_STRVAL_P(GET_STATIC_PROP(file)), 0, -1);
+ break;
+ }
+ if (ct) {
+ UPD_STATIC_PROP(string, contentType, ct);
+ RETVAL_STRING(ct, 0);
+ }