+ if (return_value_used) {
+ RETURN_PROP(responseData);
+ }
+}
+/* }}} */
+
+/* {{{ proto mixed HttpRequest::getResponseHeader([string name])
+ *
+ * Get response header(s) after the request has been sent.
+ *
+ * Accepts an string as optional parameter specifying a certain header to read.
+ * If the parameter is empty or omitted all response headers will be returned.
+ *
+ * Returns either a string with the value of the header matching name if requested,
+ * FALSE on failure, or an associative array containing all response headers.
+ *
+ * If redirects were allowed and several responses were received, the data
+ * references the last received response.
+ */
+PHP_METHOD(HttpRequest, getResponseHeader)
+{
+ if (return_value_used) {
+ zval *data, **headers, **header;
+ char *header_name = NULL;
+ int header_len = 0;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s", &header_name, &header_len)) {
+ RETURN_FALSE;
+ }
+
+ data = GET_PROP(responseData);
+ if ( (Z_TYPE_P(data) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
+ (Z_TYPE_PP(headers) == IS_ARRAY)) {
+ if (!header_len || !header_name) {
+ RETVAL_ZVAL(*headers, 1, 0);
+ } else if (SUCCESS == zend_hash_find(Z_ARRVAL_PP(headers), pretty_key(header_name, header_len, 1, 1), header_len + 1, (void *) &header)) {
+ RETVAL_ZVAL(*header, 1, 0);
+ } else {
+ RETVAL_FALSE;
+ }
+ } else {
+ RETVAL_FALSE;
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto array HttpRequest::getResponseCookies([int flags[, array allowed_extras]])
+ *
+ * Get response cookie(s) after the request has been sent.
+ *
+ * Returns an array of stdClass objects like http_parse_cookie would return.
+ *
+ * If redirects were allowed and several responses were received, the data
+ * references the last received response.
+ */
+PHP_METHOD(HttpRequest, getResponseCookies)
+{
+ if (return_value_used) {
+ long flags = 0;
+ zval *allowed_extras_array = NULL, *data, **headers;
+
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|la", &flags, &allowed_extras_array)) {
+ RETURN_FALSE;
+ }
+
+ data = GET_PROP(responseData);
+ if ( (Z_TYPE_P(data) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "headers", sizeof("headers"), (void *) &headers)) &&
+ (Z_TYPE_PP(headers) == IS_ARRAY)) {
+ int i = 0;
+ ulong idx = 0;
+ char *key = NULL, **allowed_extras = NULL;
+ zval **header = NULL, **entry = NULL;
+ HashPosition pos, pos1, pos2;
+
+ array_init(return_value);
+
+ if (allowed_extras_array) {
+ allowed_extras = ecalloc(zend_hash_num_elements(Z_ARRVAL_P(allowed_extras_array)) + 1, sizeof(char *));
+ FOREACH_VAL(pos, allowed_extras_array, entry) {
+ ZVAL_ADDREF(*entry);
+ convert_to_string_ex(entry);
+ allowed_extras[i++] = estrndup(Z_STRVAL_PP(entry), Z_STRLEN_PP(entry));
+ zval_ptr_dtor(entry);
+ }
+ }
+
+ FOREACH_HASH_KEYVAL(pos1, Z_ARRVAL_PP(headers), key, idx, header) {
+ if (key && !strcasecmp(key, "Set-Cookie")) {
+ http_cookie_list list;
+
+ if (Z_TYPE_PP(header) == IS_ARRAY) {
+ zval **single_header;
+
+ FOREACH_VAL(pos2, *header, single_header) {
+ ZVAL_ADDREF(*single_header);
+ convert_to_string_ex(single_header);
+ if (http_parse_cookie_ex(&list, Z_STRVAL_PP(single_header), flags, allowed_extras)) {
+ zval *cookie;
+
+ MAKE_STD_ZVAL(cookie);
+ object_init(cookie);
+ http_cookie_list_tostruct(&list, cookie);
+ add_next_index_zval(return_value, cookie);
+ http_cookie_list_dtor(&list);
+ }
+ zval_ptr_dtor(single_header);
+ }
+ } else {
+ ZVAL_ADDREF(*header);
+ convert_to_string_ex(header);
+ if (http_parse_cookie_ex(&list, Z_STRVAL_PP(header), flags, allowed_extras)) {
+ zval *cookie;
+
+ MAKE_STD_ZVAL(cookie);
+ object_init(cookie);
+ http_cookie_list_tostruct(&list, cookie);
+ add_next_index_zval(return_value, cookie);
+ http_cookie_list_dtor(&list);
+ }
+ zval_ptr_dtor(header);
+ }
+ }
+ /* reset key */
+ key = NULL;
+ }
+
+ if (allowed_extras) {
+ for (i = 0; allowed_extras[i]; ++i) {
+ efree(allowed_extras[i]);
+ }
+ efree(allowed_extras);
+ }
+ } else {
+ RETURN_FALSE;
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto string HttpRequest::getResponseBody()
+ *
+ * Get the response body after the request has been sent.
+ *
+ * Returns a string containing the response body.
+ *
+ * If redirects were allowed and several responses were received, the data
+ * references the last received response.
+ */
+PHP_METHOD(HttpRequest, getResponseBody)
+{
+ NO_ARGS;
+
+ if (return_value_used) {
+ zval **body;
+ zval *data = GET_PROP(responseData);
+
+ if ( (Z_TYPE_P(data) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(data), "body", sizeof("body"), (void *) &body))) {
+ RETURN_ZVAL(*body, 1, 0);
+ } else {
+ RETURN_FALSE;
+ }
+ }
+}
+/* }}} */
+
+/* {{{ proto int HttpRequest::getResponseCode()
+ *
+ * Get the response code after the request has been sent.
+ *
+ * Returns an int representing the response code.
+ *
+ * If redirects were allowed and several responses were received, the data
+ * references the last received response.
+ */
+PHP_METHOD(HttpRequest, getResponseCode)
+{
+ NO_ARGS;