- add clean_ob parameter to HttpResponse::send()
[m6w6/ext-http] / http_methods.c
index 4d7518a5ff574c3db22ca5bfb7a5ad6999a264ac..980245c6f3bca12fa4d0659d25368a16fe1ebf73 100644 (file)
@@ -40,6 +40,8 @@
 
 #ifdef ZEND_ENGINE_2
 
+#include "missing.h"
+
 ZEND_EXTERN_MODULE_GLOBALS(http)
 
 /* {{{ HttpResponse */
@@ -505,7 +507,7 @@ PHP_METHOD(HttpResponse, getFile)
 }
 /* }}} */
 
-/* {{{ proto bool HttpResponse::send()
+/* {{{ proto bool HttpResponse::send([bool clean_ob = true])
  *
  * Finally send the entity.
  *
@@ -522,14 +524,24 @@ PHP_METHOD(HttpResponse, getFile)
  */
 PHP_METHOD(HttpResponse, send)
 {
+       zend_bool clean_ob = 1;
        zval *do_cache, *do_gzip;
        getObject(http_response_object, obj);
 
-       NO_ARGS;
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|b", &clean_ob)) {
+               RETURN_FALSE;
+       }
 
        do_cache = GET_PROP(obj, cache);
        do_gzip  = GET_PROP(obj, gzip);
 
+       if (clean_ob) {
+               /* interrupt on-the-fly etag generation */
+               HTTP_G(etag).started = 0;
+               /* discard previous output buffers */
+               php_end_ob_buffers(0 TSRMLS_CC);
+       }
+
        /* gzip */
        if (Z_LVAL_P(do_gzip)) {
                php_start_ob_buffer_named("ob_gzhandler", 0, 1 TSRMLS_CC);
@@ -620,30 +632,6 @@ PHP_METHOD(HttpResponse, send)
 
 /* {{{ HttpMessage */
 
-/* {{{ proto static HttpMessage HttpMessage::fromString(string raw_message)
- *
- * Create an HttpMessage object from a string.
- */
-PHP_METHOD(HttpMessage, fromString)
-{
-       char *string = NULL;
-       int length = 0;
-       http_message *msg = NULL;
-       http_message_object obj;
-
-       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &length)) {
-               RETURN_NULL();
-       }
-
-       if (!(msg = http_message_parse(string, length))) {
-               RETURN_NULL();
-       }
-
-       Z_TYPE_P(return_value) = IS_OBJECT;
-       return_value->value.obj = http_message_object_from_msg(msg);
-}
-/* }}} */
-
 /* {{{ proto void HttpMessage::__construct([string message])
  *
  * Instantiate a new HttpMessage object.
@@ -668,6 +656,29 @@ PHP_METHOD(HttpMessage, __construct)
 }
 /* }}} */
 
+/* {{{ proto static HttpMessage HttpMessage::fromString(string raw_message)
+ *
+ * Create an HttpMessage object from a string.
+ */
+PHP_METHOD(HttpMessage, fromString)
+{
+       char *string = NULL;
+       int length = 0;
+       http_message *msg = NULL;
+
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &string, &length)) {
+               RETURN_NULL();
+       }
+
+       if (!(msg = http_message_parse(string, length))) {
+               RETURN_NULL();
+       }
+
+       Z_TYPE_P(return_value) = IS_OBJECT;
+       return_value->value.obj = http_message_object_from_msg(msg);
+}
+/* }}} */
+
 /* {{{ proto string HttpMessage::getBody()
  *
  * Get the body of the parsed Message.
@@ -889,7 +900,6 @@ PHP_METHOD(HttpMessage, getRequestUri)
        NO_ARGS;
 
        IF_RETVAL_USED {
-               zval *uri;
                getObject(http_message_object, obj);
 
                if (!HTTP_MSG_TYPE(REQUEST, obj->message)) {
@@ -972,7 +982,7 @@ PHP_METHOD(HttpMessage, getHttpVersion)
 PHP_METHOD(HttpMessage, setHttpVersion)
 {
        char v[4];
-       zval *zv, *version;
+       zval *zv;
        getObject(http_message_object, obj);
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &zv)) {
@@ -2073,7 +2083,7 @@ PHP_METHOD(HttpRequest, send)
                        php_stream_statbuf ssb;
                        zval *file = GET_PROP(obj, putFile);
 
-                       if (    (stream = php_stream_open_wrapper(Z_STRVAL_P(file), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL)) &&
+                       if (    (stream = php_stream_open_wrapper(Z_STRVAL_P(file), "rb", REPORT_ERRORS|ENFORCE_SAFE_MODE, NULL)) &&
                                        !php_stream_stat(stream, &ssb)) {
                                body.type = HTTP_REQUEST_BODY_UPLOADFILE;
                                body.data = stream;