- finish work on encoding api
[m6w6/ext-http] / http_api.c
index a5ecb12ec66fbdae50e81974a144c526ddb841b0..1eed789afe1191cc5c536c6dfd85a9f33ba78325 100644 (file)
@@ -29,8 +29,6 @@
 #      include "php_http_exception_object.h"
 #endif
 
-ZEND_EXTERN_MODULE_GLOBALS(http);
-
 PHP_MINIT_FUNCTION(http_support)
 {
        HTTP_LONG_CONSTANT("HTTP_SUPPORT", HTTP_SUPPORT);
@@ -321,6 +319,33 @@ PHP_HTTP_API STATUS _http_get_request_body_ex(char **body, size_t *length, zend_
                *body = (char *) (dup ? estrndup(SG(request_info).raw_post_data, *length) : SG(request_info).raw_post_data);
                return SUCCESS;
        }
+       
+       /* PHP only reads POST */
+       if (sapi_module.read_post) {
+               char buf[4096];
+               int len;
+               
+               while (0 < (len = sapi_module.read_post(buf, sizeof(buf) TSRMLS_CC))) {
+                       *body = erealloc(*body, *length + len + 1);
+                       memcpy(*body + *length, buf, len);
+                       *length += len;
+                       (*body)[*length] = '\0';
+               }
+               
+               /* check for error */
+               if (len >= 0) {
+                       /* connect to sapi module so it'll be freed */
+                       if (!dup) {
+                               SG(request_info).raw_post_data = *body;
+                               SG(request_info).raw_post_data_length = *length;
+                       }
+                       return SUCCESS;
+               } else {
+                       STR_FREE(*body);
+                       *length = 0;
+               }
+       }
+       
        return FAILURE;
 }
 /* }}} */