+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a/!", &new_headers)) {
+ return;
+ }
+
+ zend_hash_clean(&obj->message->hdrs);
+ if (new_headers) {
+ array_copy(Z_ARRVAL_P(new_headers), &obj->message->hdrs);
+ }
+}
+/* }}} */
+
+/* {{{ proto void HttpMessage::addHeaders(array headers[, bool append = false])
+ Add headers. If append is true, headers with the same name will be separated, else overwritten. */
+PHP_METHOD(HttpMessage, addHeaders)
+{
+ zval *new_headers;
+ zend_bool append = 0;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a|b", &new_headers, &append)) {
+ return;
+ }
+
+ array_join(Z_ARRVAL_P(new_headers), &obj->message->hdrs, append, ARRAY_JOIN_STRONLY|ARRAY_JOIN_PRETTIFY);
+}
+/* }}} */
+
+/* {{{ proto int HttpMessage::getType()
+ Get Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */
+PHP_METHOD(HttpMessage, getType)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ RETURN_LONG(obj->message->type);
+ }
+}
+/* }}} */
+
+/* {{{ proto void HttpMessage::setType(int type)
+ Set Message Type. (HTTP_MSG_NONE|HTTP_MSG_REQUEST|HTTP_MSG_RESPONSE) */
+PHP_METHOD(HttpMessage, setType)
+{
+ long type;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type)) {
+ return;
+ }
+ http_message_set_type(obj->message, type);
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getInfo(void)
+ Get the HTTP request/response line */
+PHP_METHOD(HttpMessage, getInfo)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+
+ switch (obj->message->type) {
+ case HTTP_MSG_REQUEST:
+ Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, HTTP_INFO_REQUEST_FMT_ARGS(&obj->message->http, ""));
+ break;
+ case HTTP_MSG_RESPONSE:
+ Z_STRLEN_P(return_value) = spprintf(&Z_STRVAL_P(return_value), 0, HTTP_INFO_RESPONSE_FMT_ARGS(&obj->message->http, ""));
+ break;
+ default:
+ RETURN_NULL();
+ break;
+ }
+ Z_TYPE_P(return_value) = IS_STRING;
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setInfo(string http_info)
+ Set type and request or response info with a standard HTTP request or response line */
+PHP_METHOD(HttpMessage, setInfo)
+{
+ char *str;
+ int len;
+ http_info inf;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &str, &len) && SUCCESS == http_info_parse_ex(str, &inf, 0)) {
+ getObject(http_message_object, obj);
+
+ http_message_set_info(obj->message, &inf);
+ http_info_dtor(&inf);
+ RETURN_TRUE;
+ }
+ RETURN_FALSE;
+}
+/* }}} */
+
+/* {{{ proto int HttpMessage::getResponseCode()
+ Get the Response Code of the Message. */
+PHP_METHOD(HttpMessage, getResponseCode)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+ RETURN_LONG(obj->message->http.info.response.code);
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setResponseCode(int code)
+ Set the response code of an HTTP Response Message. */
+PHP_METHOD(HttpMessage, setResponseCode)
+{
+ long code;
+ getObject(http_message_object, obj);
+
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &code)) {
+ RETURN_FALSE;
+ }
+ if (code < 100 || code > 599) {
+ http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Invalid response code (100-599): %ld", code);
+ RETURN_FALSE;
+ }
+
+ obj->message->http.info.response.code = code;
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getResponseStatus()
+ Get the Response Status of the message (i.e. the string following the response code). */
+PHP_METHOD(HttpMessage, getResponseStatus)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.response.status) {
+ RETURN_STRING(obj->message->http.info.response.status, 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setResponseStatus(string status)
+ Set the Response Status of the HTTP message (i.e. the string following the response code). */
+PHP_METHOD(HttpMessage, setResponseStatus)
+{
+ char *status;
+ int status_len;
+ getObject(http_message_object, obj);
+
+ HTTP_CHECK_MESSAGE_TYPE_RESPONSE(obj->message, RETURN_FALSE);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &status, &status_len)) {
+ RETURN_FALSE;
+ }
+ STR_SET(obj->message->http.info.response.status, estrndup(status, status_len));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestMethod()
+ Get the Request Method of the Message. */
+PHP_METHOD(HttpMessage, getRequestMethod)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.request.method) {
+ RETURN_STRING(obj->message->http.info.request.method, 1);
+ } else {
+ RETURN_EMPTY_STRING();
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto bool HttpMessage::setRequestMethod(string method)
+ Set the Request Method of the HTTP Message. */
+PHP_METHOD(HttpMessage, setRequestMethod)
+{
+ char *method;
+ int method_len;
+ getObject(http_message_object, obj);
+
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &method, &method_len)) {
+ RETURN_FALSE;
+ }
+ if (method_len < 1) {
+ http_error(HE_WARNING, HTTP_E_INVALID_PARAM, "Cannot set HttpMessage::requestMethod to an empty string");
+ RETURN_FALSE;
+ }
+ if (!http_request_method_exists(1, 0, method)) {
+ http_error_ex(HE_WARNING, HTTP_E_REQUEST_METHOD, "Unknown request method: %s", method);
+ RETURN_FALSE;
+ }
+
+ STR_SET(obj->message->http.info.request.method, estrndup(method, method_len));
+ RETURN_TRUE;
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::getRequestUrl()
+ Get the Request URL of the Message. */
+PHP_METHOD(HttpMessage, getRequestUrl)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ getObject(http_message_object, obj);
+ HTTP_CHECK_MESSAGE_TYPE_REQUEST(obj->message, RETURN_FALSE);
+ if (obj->message->http.info.request.url) {
+ RETURN_STRING(obj->message->http.info.request.url, 1);
+ } else {
+ RETURN_EMPTY_STRING();