implement #58
authorMichael Wallner <mike@php.net>
Tue, 27 Feb 2018 16:32:45 +0000 (17:32 +0100)
committerMichael Wallner <mike@php.net>
Tue, 27 Feb 2018 16:32:45 +0000 (17:32 +0100)
Client observers are now informed with an "prepare" event.
Note, though, that http\Client::getProgressInfo() does not return
the progress state received for this event.

src/php_http_client.c
src/php_http_client_curl.c
tests/client002.phpt
tests/client013.phpt

index b7cf2b90ea62aec15c468d65fa82ca8dab3094fa..0749825ba40b9b601500f299f835888e52576bb8 100644 (file)
@@ -689,7 +689,7 @@ static PHP_METHOD(HttpClient, enqueue)
        zend_fcall_info_cache fcc = empty_fcall_info_cache;
        php_http_client_object_t *obj;
        php_http_message_object_t *msg_obj;
-       php_http_client_enqueue_t q;
+       php_http_client_enqueue_t q = {0};
 
        php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "O|f", &request, php_http_get_client_request_class_entry(), &fci, &fcc), invalid_arg, return);
 
@@ -701,6 +701,17 @@ static PHP_METHOD(HttpClient, enqueue)
                return;
        }
 
+       /* set early for progress callback */
+       q.opaque = msg_obj;
+
+       if (obj->client->callback.progress.func) {
+               php_http_client_progress_state_t progress = {0};
+
+               progress.info = "prepare";
+               obj->client->callback.progress.func(obj->client->callback.progress.arg, obj->client, &q, &progress);
+       }
+
+       Z_ADDREF_P(request);
        q.request = msg_obj->message;
        q.options = combined_options(getThis(), request);
        q.dtor = msg_queue_dtor;
@@ -715,8 +726,6 @@ static PHP_METHOD(HttpClient, enqueue)
                }
        }
 
-       Z_ADDREF_P(request);
-
        php_http_expect(SUCCESS == php_http_client_enqueue(obj->client, &q), runtime,
                        msg_queue_dtor(&q);
                        return;
index f07b5b822e1a72f57e55f7ba5ea7b70357f1a420..b17d8a6927f30d7cf6c5d15165eba3927584a2e1 100644 (file)
@@ -218,6 +218,7 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
        switch (type) {
                case CURLINFO_TEXT:
                        if (data[0] == '-') {
+                               goto text;
                        } else if (php_memnstr(data, ZEND_STRL("Adding handle:"), data + length)) {
                                h->progress.info = "setup";
                        } else if (php_memnstr(data, ZEND_STRL("addHandle"), data + length)) {
@@ -234,8 +235,16 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                                h->progress.info = "connected";
                        } else if (php_memnstr(data, ZEND_STRL("blacklisted"), data + length)) {
                                h->progress.info = "blacklist check";
+                       } else if (php_memnstr(data, ZEND_STRL("TLS"), data + length)) {
+                               h->progress.info = "ssl negotiation";
                        } else if (php_memnstr(data, ZEND_STRL("SSL"), data + length)) {
                                h->progress.info = "ssl negotiation";
+                       } else if (php_memnstr(data, ZEND_STRL("certificate"), data + length)) {
+                               h->progress.info = "ssl negotiation";
+                       } else if (php_memnstr(data, ZEND_STRL("ALPN"), data + length)) {
+                               h->progress.info = "alpn";
+                       } else if (php_memnstr(data, ZEND_STRL("NPN"), data + length)) {
+                               h->progress.info = "npn";
                        } else if (php_memnstr(data, ZEND_STRL("upload"), data + length)) {
                                h->progress.info = "uploaded";
                        } else if (php_memnstr(data, ZEND_STRL("left intact"), data + length)) {
@@ -247,6 +256,7 @@ static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data,
                        } else if (php_memnstr(data, ZEND_STRL("Operation timed out"), data + length)) {
                                h->progress.info = "timeout";
                        } else {
+                               text:;
 #if 0
                                h->progress.info = data;
                                data[length - 1] = '\0';
index aeb2d8ac7041e888475178b190db8175823f63b5..6f01a444e97a20d72e95bb6edf1a84c26b659e5d 100644 (file)
@@ -16,7 +16,7 @@ class Observer implements SplObserver
 {
        function update(SplSubject $client, http\Client\Request $request = null, StdClass $progress = null) {
                echo "P";
-               if ($client->getProgressInfo($request) != $progress) {
+               if ($progress->info !== "prepare" && $client->getProgressInfo($request) != $progress) {
                        var_dump($progress);
                }
        }
index fdf6c969c37587884ebc472214e21c3598335a50..477edf7fa6d18122efbe919c5b8be69b61382ba3 100644 (file)
@@ -43,6 +43,9 @@ server("proxy.inc", function($port) {
                        $o3 = new CallbackObserver(
                                        function ($c, $r) {
                                                $p = (array) $c->getProgressInfo($r);
+                                               if (!$p) {
+                                                       return;
+                                               }
                                                var_dump(array_key_exists("started", $p));
                                                var_dump(array_key_exists("finished", $p));
                                                var_dump(array_key_exists("dlnow", $p));