<p>Set the HTTP Protocol version of the Message.</p>
<p>Expects a string parameter containing the HTTP protocol version.</p>
<p>Returns TRUE on success, or FALSE if supplied version is out of range (1.0/1.1).</p>
+<h3 id="HttpMessage_guessContentType">string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])</h3>
+<p>Attempts to guess the content type of supplied payload through libmagic.</p>
+<p>Expects a string parameter specifying the magic.mime database to use.<br />
+Additionally accepts an optional int parameter, being flags for libmagic.</p>
+<p>Returns the guessed content type on success, or FALSE on failure.</p>
+<p>Throws HttpRuntimeException, HttpInvalidParamException <br />
+if http.only_exceptions is TRUE.</p>
<h3 id="HttpMessage_getParentMessage">HttpMessage HttpMessage::getParentMessage()</h3>
<p>Get parent Message.</p>
<p>Returns the parent HttpMessage on success, or NULL if there's none.</p>
<li><a href="#HttpMessage_setRequestUrl">HttpMessage::setRequestUrl()</a></li>
<li><a href="#HttpMessage_getHttpVersion">HttpMessage::getHttpVersion()</a></li>
<li><a href="#HttpMessage_setHttpVersion">HttpMessage::setHttpVersion()</a></li>
+<li><a href="#HttpMessage_guessContentType">HttpMessage::guessContentType()</a></li>
<li><a href="#HttpMessage_getParentMessage">HttpMessage::getParentMessage()</a></li>
<li><a href="#HttpMessage_send">HttpMessage::send()</a></li>
<li><a href="#HttpMessage_toString">HttpMessage::toString()</a></li>
</li>
</ul>
</div>
- <p><b>Generated at: Sun, 28 May 2006 17:55:39 +0200</b></p>
+ <p><b>Generated at: Thu, 08 Jun 2006 23:59:56 +0200</b></p>
</body>
</html>
#define HTTP_WANT_SAPI
#define HTTP_WANT_CURL
+#define HTTP_WANT_MAGIC
#include "php_http.h"
#ifdef ZEND_ENGINE_2
HTTP_ARG_VAL(http_version, 0)
HTTP_END_ARGS;
+HTTP_BEGIN_ARGS(guessContentType, 1)
+ HTTP_ARG_VAL(magic_file, 0)
+ HTTP_ARG_VAL(magic_mode, 0)
+HTTP_END_ARGS;
+
HTTP_EMPTY_ARGS(getParentMessage);
HTTP_EMPTY_ARGS(send);
HTTP_BEGIN_ARGS(toString, 0)
HTTP_MESSAGE_ME(setRequestUrl, ZEND_ACC_PUBLIC)
HTTP_MESSAGE_ME(getHttpVersion, ZEND_ACC_PUBLIC)
HTTP_MESSAGE_ME(setHttpVersion, ZEND_ACC_PUBLIC)
+ HTTP_MESSAGE_ME(guessContentType, ZEND_ACC_PUBLIC)
HTTP_MESSAGE_ME(getParentMessage, ZEND_ACC_PUBLIC)
HTTP_MESSAGE_ME(send, ZEND_ACC_PUBLIC)
HTTP_MESSAGE_ME(toString, ZEND_ACC_PUBLIC)
}
/* }}} */
+/* {{{ proto string HttpMessage::guessContentType(string magic_file[, int magic_mode = MAGIC_MIME])
+ *
+ * Attempts to guess the content type of supplied payload through libmagic.
+ *
+ * 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(HttpMessage, guessContentType)
+{
+#ifdef HTTP_HAVE_MAGIC
+ char *magic_file, *ct = NULL;
+ int magic_file_len;
+ long magic_mode = MAGIC_MIME;
+
+ RETVAL_FALSE;
+ SET_EH_THROW_HTTP();
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &magic_file, &magic_file_len, &magic_mode)) {
+ getObject(http_message_object, obj);
+ if ((ct = http_guess_content_type(magic_file, magic_mode, PHPSTR_VAL(&obj->message->body), PHPSTR_LEN(&obj->message->body), SEND_DATA))) {
+ RETVAL_STRING(ct, 0);
+ }
+ }
+ SET_EH_NORMAL();
+#else
+ http_error(HE_THROW, HTTP_E_RUNTIME, "Cannot guess Content-Type; libmagic not available");
+ RETURN_FALSE;
+#endif
+}
+/* }}} */
+
/* {{{ proto HttpMessage HttpMessage::getParentMessage()
*
* Get parent Message.
char *ct = NULL;
#ifdef HTTP_HAVE_MAGIC
- struct magic_set *magic;
+ struct magic_set *magic = NULL;
HTTP_CHECK_OPEN_BASEDIR(magicfile, return NULL);
- /* magic_load() fails if MAGIC_MIME is set because it
- cowardly adds .mime to the file name */
- magic = magic_open(magicmode &~ MAGIC_MIME);
-
- if (!magic) {
+ if (!data_ptr) {
+ http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Supplied payload is empty");
+ } else if (!(magic = magic_open(magicmode &~ MAGIC_MIME))) {
http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid magic mode: %ld", magicmode);
} else if (-1 == magic_load(magic, magicfile)) {
http_error_ex(HE_WARNING, HTTP_E_RUNTIME, "Failed to load magic database '%s' (%s)", magicfile, magic_error(magic));
HTTP_ARG_VAL(encoded_string, 0)
HTTP_END_ARGS;
+#ifdef HTTP_HAVE_ZLIB
HTTP_BEGIN_ARGS(deflate, 1)
HTTP_ARG_VAL(plain, 0)
HTTP_ARG_VAL(flags, 0)
HTTP_BEGIN_ARGS(inflate, 1)
HTTP_ARG_VAL(encoded, 0)
HTTP_END_ARGS;
+#endif
HTTP_BEGIN_ARGS(support, 0)
HTTP_ARG_VAL(feature, 0)
</maintainer>
</maintainers>
<release>
- <version>1.0.0RC5</version>
- <date>2006-05-28</date>
+ <version>1.0.0</version>
+ <date>2006-06-09</date>
<license>BSD, revised</license>
- <state>beta</state>
- <notes>+ Added HttpRequest::enableCookies() and HttpRequest::resetCookies([bool session_only=FALSE])
-+ Added optional flags argument to http_parse_params()
-+ Added HTTP_PARAMS_ALLOW_COMMA, HTTP_PARAMS_ALLOW_FAILURE, HTTP_PARAMS_RAISE_ERROR constants
-* Fixed http_build_url("./path") if REQUEST_URI is empty
-* Fixed http_parse_params("foo;bar") returning "foo" and "ar"
-* Fixed return value of http_parse_params() Object{"params"=>Array("value", Array("name"=>"value"), ...)}
-* Fixed HttpMessage::setRequestMethod() errenously issuing a warning about an unknown request method
-* Fixed bugs introduced by using the new REQUEST_TIME server variable
-! NOTE: Many INI settings have been renamed to comply with the internal structure
+ <state>stable</state>
+ <notes>+ Added --with[out]-http-shared-deps configure option (dependencies on shared extensions)
++ Added INI entries: http.log.not_found, http.send.not_found_404
++ Added HttpMessage::guessContentType()
+* Fixed build on Debian systems where access to Curl_* functions is prohibited
+* Fixed empty Cache-Control header if not customly set with HttpResponse
+* Reset Content-Disposition and Content-Type if file is not found by http_send_file() etc
</notes>
<deps>
<dep type="php" rel="ge" version="4.3"/>
</deps>
<configureoptions>
<configureoption name="with-http-curl-requests" default="yes" prompt="whether to enable cURL HTTP requests; specify libcurl directory"/>
- <configureoption name="with-http-magic-mime" default="no" prompt="whether to enable response content type guessing; specify libmagic directory"/>
<configureoption name="with-http-zlib-compression" default="yes" prompt="whether to enable support for gzencoded/deflated message bodies; specify zlib directory"/>
+ <configureoption name="with-http-magic-mime" default="no" prompt="whether to enable response content type guessing; specify libmagic directory"/>
+ <configureoption name="with-http-shared-deps" default="yes" prompt="whether to depend on extensions which have been built shared"/>
</configureoptions>
<filelist>
<dir name="docs">
<file role="php" install-as="pecl/http/FeedAggregator.php" name="FeedAggregator.php"/>
<file role="php" install-as="pecl/http/PgLobStream.php" name="PgLobStream.php"/>
<file role="php" install-as="pecl/http/XmlRpcClient.php" name="XmlRpcClient.php"/>
+ <file role="php" install-as="pecl/http/XmlRpcServer.php" name="XmlRpcServer.php"/>
</dir> <!-- /lib -->
<dir name="phpstr">
<file role="src" name="phpstr.c"/>
<file role="test" name="HttpResponse_002.phpt"/>
<file role="test" name="HttpResponse_003.phpt"/>
<file role="test" name="HttpResponse_004.phpt"/>
+ <file role="test" name="HttpResponse_005.phpt"/>
<file role="test" name="log.inc"/>
<file role="test" name="match_request_header_001.phpt"/>
<file role="test" name="negotiation_001.phpt"/>
</dir> <!-- /tests -->
<file role="src" name="config.m4"/>
<file role="src" name="config.w32"/>
+ <file role="src" name="config9.m4"/>
<file role="doc" name="CREDITS"/>
<file role="doc" name="EXPERIMENTAL"/>
<file role="src" name="http.c"/>
<file role="src" name="php_http_requestpool_object.h"/>
<file role="src" name="php_http_request_api.h"/>
<file role="src" name="php_http_request_body_api.h"/>
+ <file role="src" name="php_http_request_int.h"/>
<file role="src" name="php_http_request_method_api.h"/>
<file role="src" name="php_http_request_object.h"/>
<file role="src" name="php_http_request_pool_api.h"/>
</lead>
<date>2006-00-00</date>
<version>
- <release>1.0.0dev</release>
+ <release>1.0.0</release>
<api>1.0.0</api>
</version>
<stability>
- <release>beta</release>
- <api>beta</api>
+ <release>stable</release>
+ <api>stable</api>
</stability>
<license>BSD, revised</license>
<notes><![CDATA[
+ Added --with[out]-http-shared-deps configure option (dependencies on shared extensions)
+ Added INI entries: http.log.not_found, http.send.not_found_404
++ Added HttpMessage::guessContentType()
* Fixed build on Debian systems where access to Curl_* functions is prohibited
* Fixed empty Cache-Control header if not customly set with HttpResponse
* Reset Content-Disposition and Content-Type if file is not found by http_send_file() etc
<file role="php" name="FeedAggregator.php"/>
<file role="php" name="PgLobStream.php"/>
<file role="php" name="XmlRpcClient.php"/>
+ <file role="php" name="XmlRpcServer.php"/>
</dir>
<dir name="tests">
<install as="pecl/http/FeedAggregator.php" name="lib/FeedAggregator.php"/>
<install as="pecl/http/PgLobStream.php" name="lib/PgLobStream.php"/>
<install as="pecl/http/XmlRpcClient.php" name="lib/XmlRpcClient.php"/>
+ <install as="pecl/http/XmlRpcServer.php" name="lib/XmlRpcServer.php"/>
</filelist>
</extsrcrelease>
<changelog />
PHP_METHOD(HttpMessage, setRequestUrl);
PHP_METHOD(HttpMessage, getHttpVersion);
PHP_METHOD(HttpMessage, setHttpVersion);
+PHP_METHOD(HttpMessage, guessContentType);
PHP_METHOD(HttpMessage, getParentMessage);
PHP_METHOD(HttpMessage, send);
PHP_METHOD(HttpMessage, toString);
<?php
include 'skip.inc';
checkmin(5);
+checkcls("HttpRequest");
?>
--FILE--
<?php