code cleanup
[m6w6/ext-http] / php_http_curl_client.c
index a285397fb124613cee728fea306b8343dcb8c790..ce47f6b2163fb8caa1be17cdb761fd1104fe14c1 100644 (file)
@@ -1024,8 +1024,9 @@ static STATUS php_http_curl_client_reset(php_http_client_t *h)
        return SUCCESS;
 }
 
-STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *msg)
+PHP_HTTP_API STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *msg)
 {
+       size_t body_size;
        php_http_curl_client_t *curl = h->ctx;
        php_http_curl_client_storage_t *storage = get_storage(curl->handle);
        TSRMLS_FETCH_FROM_CTX(h->ts);
@@ -1096,15 +1097,14 @@ STATUS php_http_curl_client_prepare(php_http_client_t *h, php_http_message_t *ms
        }
 
        /* attach request body */
-       {
+       if ((body_size = php_http_message_body_size(&msg->body))) {
                /* RFC2616, section 4.3 (para. 4) states that »a message-body MUST NOT be included in a request if the
                 * specification of the request method (section 5.1.1) does not allow sending an entity-body in request.«
                 * Following the clause in section 5.1.1 (para. 2) that request methods »MUST be implemented with the
                 * same semantics as those specified in section 9« reveal that not any single defined HTTP/1.1 method
                 * does not allow a request body.
                 */
-               size_t body_size = php_http_message_body_size(&msg->body);
-
+               php_stream_rewind(php_http_message_body_stream(&msg->body));
                curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, &msg->body);
                curl_easy_setopt(curl->handle, CURLOPT_READDATA, &msg->body);
                curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
@@ -1245,11 +1245,6 @@ static php_http_resource_factory_ops_t php_http_curl_client_resource_factory_ops
        php_http_curl_dtor
 };
 
-static zend_class_entry *get_class_entry(void)
-{
-       return php_http_curl_client_class_entry;
-}
-
 static php_http_client_ops_t php_http_curl_client_ops = {
        &php_http_curl_client_resource_factory_ops,
        php_http_curl_client_init,
@@ -1260,7 +1255,7 @@ static php_http_client_ops_t php_http_curl_client_ops = {
        php_http_curl_client_setopt,
        php_http_curl_client_getopt,
        (php_http_new_t) php_http_curl_client_object_new_ex,
-       get_class_entry
+       php_http_curl_client_get_class_entry
 };
 
 PHP_HTTP_API php_http_client_ops_t *php_http_curl_client_get_ops(void)
@@ -1278,8 +1273,14 @@ PHP_HTTP_BEGIN_ARGS(send, 1)
        PHP_HTTP_ARG_VAL(request, 0)
 PHP_HTTP_END_ARGS;
 
-zend_class_entry *php_http_curl_client_class_entry;
-zend_function_entry php_http_curl_client_method_entry[] = {
+static zend_class_entry *php_http_curl_client_class_entry;
+
+zend_class_entry *php_http_curl_client_get_class_entry(void)
+{
+       return php_http_curl_client_class_entry;
+}
+
+static zend_function_entry php_http_curl_client_method_entry[] = {
        PHP_HTTP_CURL_CLIENT_CLIENT_MALIAS(send, ZEND_ACC_PUBLIC)
        EMPTY_FUNCTION_ENTRY
 };