- update
[m6w6/ext-http] / http_methods.c
index 1b2d80b786dc9c1a701fbcb66f33338e4b522d3e..a6e2f2007ff3fc0453f9fc6b455c8161c2661d57 100644 (file)
 #include "php_http_send_api.h"
 #include "php_http_url_api.h"
 
+#include "php_http_message_object.h"
+#include "php_http_response_object.h"
+#include "php_http_request_object.h"
+
 #ifdef ZEND_ENGINE_2
 
 /* {{{ HttpResponse */
@@ -517,6 +521,83 @@ PHP_METHOD(HttpResponse, send)
 /* }}} */
 /* }}} */
 
+/* {{{ HttpMessage */
+
+/* {{{ void HttpMessage::__construct([string raw_message])
+ *
+ * Instantiate a new HttpMessage object based on the optionally provided
+ * raw message.  An HTTP Message can be either a response or a request.
+ */
+PHP_METHOD(HttpMessage, __construct)
+{
+       zval *message = NULL;
+       int message_len;
+       getObject(http_message_object, obj);
+
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z/", &message)) {
+               return;
+       }
+
+       if (message) {
+               convert_to_string(message);
+               SET_PROP(obj, raw, message);
+       }
+}
+/* }}} */
+
+/* {{{ void HttpMessage::setRaw(string raw_message)
+ *
+ * Parse a new raw message.
+ */
+PHP_METHOD(HttpMessage, setRaw)
+{
+       zval *message;
+       getObject(http_message_object, obj);
+       
+       if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z/", &message)) {
+               return;
+       }
+
+       convert_to_string(message);
+       SET_PROP(obj, raw, message);
+}
+/* }}} */
+
+/* {{{ string HttpMessage::getBody()
+ *
+ * Get the body of the parsed Message.
+ */
+PHP_METHOD(HttpMessage, getBody)
+{
+       zval *body;
+       getObject(http_message_object, obj);
+       
+       NO_ARGS;
+
+       body = GET_PROP(obj, body);
+       RETURN_STRINGL(Z_STRVAL_P(body), Z_STRLEN_P(body), 1);
+}
+/* }}} */
+
+/* {{{ array HttpMessage::getHeaders()
+ *
+ * Get Message Headers.
+ */
+PHP_METHOD(HttpMessage, getHeaders)
+{
+       zval *headers;
+       getObject(http_message_object, obj);
+       
+       NO_ARGS;
+       
+       headers = GET_PROP(obj, headers);
+       array_init(return_value);
+       array_copy(headers, return_value);
+}
+/* }}} */
+
+/* }}} */
+
 #ifdef HTTP_HAVE_CURL
 /* {{{ HttpRequest */
 
@@ -1358,7 +1439,7 @@ PHP_METHOD(HttpRequest, getResponseCode)
 
        data = GET_PROP(obj, responseData);
        if (    (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void **) &hdrs)) &&
-                       (SUCCESS == zend_hash_find(Z_ARRVAL_PP(hdrs), "Status", sizeof("Status"), (void **) &code))) {
+                       (SUCCESS == zend_hash_find(Z_ARRVAL_PP(hdrs), "Response Status", sizeof("Response Status"), (void **) &code))) {
                RETVAL_STRINGL(Z_STRVAL_PP(code), Z_STRLEN_PP(code), 1);
                convert_to_long(return_value);
        } else {