duh, test before commit!; remove errenous additional CRLF on php_http_message_to_stri...
authorMichael Wallner <mike@php.net>
Thu, 15 Mar 2012 15:29:27 +0000 (15:29 +0000)
committerMichael Wallner <mike@php.net>
Thu, 15 Mar 2012 15:29:27 +0000 (15:29 +0000)
php_http_message.c
php_http_message_body.c
phpunit/MessageBodyTest.php
tests/message001.phpt
tests/message002.phpt
tests/message003.phpt

index 58d8ee9d05c785cb46494e9eaefbd0d60cd4a530..2c25aec7c7c431326302c999bce418be0fde8741 100644 (file)
@@ -393,7 +393,6 @@ PHP_HTTP_API void php_http_message_to_callback(php_http_message_t *msg, php_http
        if (php_http_message_body_size(&msg->body)) {
                cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF));
                php_http_message_body_to_callback(&msg->body, cb, cb_arg, 0, 0);
-               cb(cb_arg, ZEND_STRL(PHP_HTTP_CRLF));
        }
 }
 
@@ -407,7 +406,6 @@ PHP_HTTP_API void php_http_message_to_string(php_http_message_t *msg, char **str
        if (php_http_message_body_size(&msg->body)) {
                php_http_buffer_appends(&str, PHP_HTTP_CRLF);
                php_http_message_body_to_callback(&msg->body, (php_http_pass_callback_t) php_http_buffer_append, &str, 0, 0);
-               php_http_buffer_appends(&str, PHP_HTTP_CRLF);
        }
 
        data = php_http_buffer_data(&str, string, length);
@@ -428,6 +426,7 @@ PHP_HTTP_API void php_http_message_serialize(php_http_message_t *message, char *
 
        do {
                php_http_message_to_string(message, &buf, &len);
+               php_http_buffer_prepends(&str, PHP_HTTP_CRLF);
                php_http_buffer_prepend(&str, buf, len);
                efree(buf);
        } while ((message = message->parent));
index e1a0288f51aee80d5295f3f5867419e6f2a23548..0374df3027088be4ee3feca88587e62c20ba8585 100644 (file)
@@ -553,7 +553,7 @@ PHP_HTTP_BEGIN_ARGS(addForm, 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_BEGIN_ARGS(addPart, 1)
-       PHP_HTTP_ARG_OBJ("http\\Message", "message", 0)
+       PHP_HTTP_ARG_OBJ(http\\Message, "message", 0)
 PHP_HTTP_END_ARGS;
 
 PHP_HTTP_EMPTY_ARGS(etag);
@@ -767,10 +767,11 @@ PHP_METHOD(HttpMessageBody, addForm)
 
 PHP_METHOD(HttpMessageBody, addPart)
 {
-       php_http_message_object_t *mobj;
+       zval *zobj;
 
-       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &mobj, php_http_message_class_entry)) {
+       if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O", &zobj, php_http_message_class_entry)) {
                php_http_message_body_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+               php_http_message_object_t *mobj = zend_object_store_get_object(zobj TSRMLS_CC);
 
                php_http_message_body_add_part(obj->body, mobj->message);
                RETURN_TRUE;
index 4ef4efe43814f7f2a9c0ed0018c1d5247b2b17ce..cc0f421efd9f92c31d2d9d7cd76999773b563a20 100644 (file)
@@ -78,6 +78,20 @@ class MessageBodyTest extends PHPUnit_Framework_TestCase {
         );
     }
 
+    function testAddPart() {
+        $this->temp->addPart(new http\Message("This: is a header\n\nand this is the data\n"));
+        $this->assertStringMatchesFormat(
+            "--%x.%x\r\n".
+            "This: is a header\r\n".
+            "Content-Length: 21\r\n".
+            "\r\n".
+            "and this is the data\n\r\n".
+            "--%x.%x--\r\n".
+            "",
+            str_replace("\r", "", $this->temp)
+        );
+    }
+
     function testEtag() {
         $s = stat(__FILE__);
         $this->assertEquals(
index 7b6b534d8e5d59f89633f8393059639a56abb0e1..aa01e6d53e0302deb62831272d9f33ef5c25dc17 100644 (file)
@@ -239,7 +239,6 @@ X-Original-Transfer-Encoding: chunked
 Content-Length: 14
 
 Hello, World!
-
 string(3) "1.1"
 bool(true)
 int(200)
index 005f09898201e2c6d04b1d11654db26dc8a9e4b7..dcaacf3d4b4d2e0f18917654d4215ab81e41f486 100644 (file)
@@ -18,7 +18,7 @@ use http\env\Request as HttpEnvRequest;
 $m = new HttpEnvRequest();
 
 var_dump($m);
-echo $m;
+echo $m,"\n";
 
 var_dump((string)$m->getBody());
 
@@ -80,8 +80,10 @@ object(%s)#%d (13) {
 }
 POST / HTTP/1.1%a
 X-Test: test%a
+Content-Length: 3%a
+Content-Type: test/something%a
 Cookie: foo=bar%a
 %a
-b=c%a
+b=c
 string(3) "b=c"
 Done
index 0ce10b21af72e35d2edb0b7eafe47ce38173bb3a..2f2b514522b40e4b872f7fb07157a7ac5d8f9a15 100644 (file)
@@ -45,7 +45,6 @@ Content-Length: 567
     }
 }
 
-
 ===
 ===
 Content-Disposition: form-data; name="LICENSE"; filename="LICENSE"
@@ -76,6 +75,5 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
-
 ===
 DONE