- added http_get_request_body()
authorMichael Wallner <mike@php.net>
Tue, 19 Jul 2005 15:57:44 +0000 (15:57 +0000)
committerMichael Wallner <mike@php.net>
Tue, 19 Jul 2005 15:57:44 +0000 (15:57 +0000)
http.c
http_api.c
http_functions.c
http_util_object.c
php_http.h
php_http_api.h
php_http_util_object.h

diff --git a/http.c b/http.c
index 4460d6950d2bd540d78d143c92af23925c99a785..3e7baeb137242888f1ca33ca470bf7d78f1477e5 100644 (file)
--- a/http.c
+++ b/http.c
@@ -85,6 +85,7 @@ function_entry http_functions[] = {
        PHP_FE(http_split_response, NULL)
        PHP_FE(http_parse_headers, NULL)
        PHP_FE(http_get_request_headers, NULL)
+       PHP_FE(http_get_request_body, NULL)
        PHP_FE(http_match_request_header, NULL)
 #ifdef HTTP_HAVE_CURL
        PHP_FE(http_get, http_arg_pass_ref_3)
index 5bf39207c4ee7ce10630ddc1f8452c5cc9902679..d943b0df01e3d6afbdae98a407c79267e48a530f 100644 (file)
@@ -24,6 +24,8 @@
 #include "php.h"
 #include "ext/standard/url.h"
 
+#include "SAPI.h"
+
 #include "php_http.h"
 #include "php_http_std_defs.h"
 #include "php_http_api.h"
@@ -226,6 +228,20 @@ PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zen
 }
 /* }}} */
 
+/* {{{ zend_bool http_get_request_body(char **, size_t *) */
+PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC)
+{
+       *length = 0;
+       *body = NULL;
+
+       if (SG(request_info).raw_post_data) {
+               *length = SG(request_info).raw_post_data_length;
+               *body = (char *) (dup ? estrndup(SG(request_info).raw_post_data, *length) : SG(request_info).raw_post_data);
+               return SUCCESS;
+       }
+       return FAILURE;
+}
+/* }}} */
 
 /* {{{ char *http_chunked_decode(char *, size_t, char **, size_t *) */
 PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len,
index 8e27b767ab08d11ae123b9aa074120c5ec83c6c6..4e67be7aee3fac005c0e2f083d096c94e0986b60 100644 (file)
@@ -663,6 +663,25 @@ PHP_FUNCTION(http_get_request_headers)
 }
 /* }}} */
 
+/* {{{ proto string http_get_request_body(void)
+ *
+ * Get the raw request body (e.g. POST or PUT data).
+ */
+PHP_FUNCTION(http_get_request_body)
+{
+       char *body;
+       size_t length;
+
+       NO_ARGS;
+
+       if (SUCCESS == http_get_request_body(&body, &length)) {
+               RETURN_STRING(body, (int) length, 0);
+       } else {
+               RETURN_NULL();
+       }
+}
+/* }}} */
+
 /* {{{ proto bool http_match_request_header(string header, string value[, bool match_case = false])
  *
  * Match an incoming HTTP header.
index adae1b01e1fab9b8a7419da58d001ab726c2e738..123c83d59cdd9a82d5fd2bed94f7d0848d7d6200 100644 (file)
@@ -48,6 +48,7 @@ zend_function_entry http_util_object_fe[] = {
        HTTP_STATIC_ME_ALIAS(splitResponse, http_split_response, NULL)
        HTTP_STATIC_ME_ALIAS(parseHeaders, http_parse_headers, NULL)
        HTTP_STATIC_ME_ALIAS(getRequestHeaders, http_get_request_headers, NULL)
+       HTTP_STATIC_ME_ALIAS(getRequestBody, http_get_request_body, NULL)
 #ifdef HTTP_HAVE_CURL
        HTTP_STATIC_ME_ALIAS(get, http_get, http_arg_pass_ref_3)
        HTTP_STATIC_ME_ALIAS(head, http_head, http_arg_pass_ref_3)
index 409bcc23a3b1f5d639113e6b48c22d93f0ad0ee1..8aa524bb48f828a6b9debe102f19da1c74cb5a51 100644 (file)
@@ -106,6 +106,7 @@ PHP_FUNCTION(http_chunked_decode);
 PHP_FUNCTION(http_split_response);
 PHP_FUNCTION(http_parse_headers);
 PHP_FUNCTION(http_get_request_headers);
+PHP_FUNCTION(http_get_request_body);
 PHP_FUNCTION(http_match_request_header);
 #ifdef HTTP_HAVE_CURL
 PHP_FUNCTION(http_get);
index bd229e3f4d11c0798fe0fe7f388581b8af25be25..472c4b902b7e8559f9f1c691757aa030f4ac8aa9 100644 (file)
@@ -53,6 +53,10 @@ extern STATUS _http_check_method_ex(const char *method, const char *methods);
 #define http_get_server_var_ex(v, s) _http_get_server_var_ex((v), (s), 0 TSRMLS_CC)
 PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC);
 
+#define http_get_request_body(b, l) _http_get_request_body_ex((b), (l), 1 TSRMLS_CC)
+#define http_get_Request_body_ex(b, l, d) _http_get_request_body_ex((b), (l), (d) TSRMLS_CC)
+PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_bool dup TSRMLS_DC);
+
 #define http_chunked_decode(e, el, d, dl) _http_chunked_decode((e), (el), (d), (dl) TSRMLS_CC)
 PHP_HTTP_API const char *_http_chunked_decode(const char *encoded, size_t encoded_len, char **decoded, size_t *decoded_len TSRMLS_DC);
 
index 080fa8bcf93a29a732f8c785c14d5f239985acfd..d89c38fb535638fea104779c4e78c4d9cdee055b 100644 (file)
@@ -42,6 +42,7 @@ PHP_METHOD(HttpUtil, chunkedDecode);
 PHP_METHOD(HttpUtil, splitResponse);
 PHP_METHOD(HttpUtil, parseHeaders);
 PHP_METHOD(HttpUtil, getRequestHeaders);
+PHP_METHOD(HttpUtil, getRequestBody);
 #ifdef HTTP_HAVE_CURL
 PHP_METHOD(HttpUtil, get);
 PHP_METHOD(HttpUtil, head);