From: Michael Wallner Date: Thu, 15 Mar 2012 15:29:27 +0000 (+0000) Subject: duh, test before commit!; remove errenous additional CRLF on php_http_message_to_stri... X-Git-Tag: DEV_2-before-client~17 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=ae3da9e40ac118dc77984bfe172aa0ddc0a49a48;p=m6w6%2Fext-http duh, test before commit!; remove errenous additional CRLF on php_http_message_to_string(); fix some tests while at --- diff --git a/php_http_message.c b/php_http_message.c index 58d8ee9..2c25aec 100644 --- a/php_http_message.c +++ b/php_http_message.c @@ -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)); diff --git a/php_http_message_body.c b/php_http_message_body.c index e1a0288..0374df3 100644 --- a/php_http_message_body.c +++ b/php_http_message_body.c @@ -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; diff --git a/phpunit/MessageBodyTest.php b/phpunit/MessageBodyTest.php index 4ef4efe..cc0f421 100644 --- a/phpunit/MessageBodyTest.php +++ b/phpunit/MessageBodyTest.php @@ -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( diff --git a/tests/message001.phpt b/tests/message001.phpt index 7b6b534..aa01e6d 100644 --- a/tests/message001.phpt +++ b/tests/message001.phpt @@ -239,7 +239,6 @@ X-Original-Transfer-Encoding: chunked Content-Length: 14 Hello, World! - string(3) "1.1" bool(true) int(200) diff --git a/tests/message002.phpt b/tests/message002.phpt index 005f098..dcaacf3 100644 --- a/tests/message002.phpt +++ b/tests/message002.phpt @@ -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 diff --git a/tests/message003.phpt b/tests/message003.phpt index 0ce10b2..2f2b514 100644 --- a/tests/message003.phpt +++ b/tests/message003.phpt @@ -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