Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VKClientException: Invalid http status: 0 при работе через HTTP/2 #36

Closed
Nik-mmzd opened this issue Dec 19, 2018 · 6 comments

Comments

@Nik-mmzd
Copy link

https://github.com/VKCOM/vk-php-sdk/blob/master/src/VK/TransportClient/Curl/CurlHttpClient.php#L187
Не может распарсить HTTP status code при запросе через HTTP/2 (HTTP/2 401 не попадает под регулярку)

3aBXo3 added a commit to 3aBXo3/vk-php-sdk that referenced this issue Dec 28, 2018
Для получения статуса последнего HTTP ответа, вместо регулярного выражения, использована функция cURL.
@zakharov-dm
Copy link

Да, та же проблема.

tsivarev added a commit that referenced this issue Dec 29, 2018
@mrzlab630
Copy link

мое решение:

protected function getHttpStatus(string $raw_response_header): int {
preg_match('@HTTP/(\d|\d.\d)\s+(\d+)\s+.*@', $raw_response_header, $match);
return (int)$match[2];
}

  1. изменил регулярку с |HTTP/\d.\d\s+(\d+)\s+.| на @HTTP/(\d|\d.\d)\s+(\d+)\s+.@
  2. $match[2]

@Nik-mmzd
Copy link
Author

@mihver1
Во-первых, куда более правильный метод уже в PR: #38
Во-вторых, в Dev уже пофикшено: 69a9448

@sizeg
Copy link

sizeg commented May 1, 2020

@Nik-mmzd проблема актуальна. Проект заброшен?

VK/TransportClient/Curl/CurlHttpClient::getHttpStatus("HTTP/2 200")

Релиз 5.101.0
PHP 7.4

PHP Fatal error: Uncaught VKExceptionsVKClientException: Invalid http status: 0
in /var/www/vendor/vkcom/vk-php-sdk/src/VK/Client/VKApiRequest.php:184
Stack trace:

 #0 /var/www/vendor/vkcom/vk-php-sdk/src/VK/Client/VKApiRequest.php(124): VKClientVKApiRequest->checkHttpStatus()
 #1 /var/www/vendor/vkcom/vk-php-sdk/src/VK/Client/VKApiRequest.php(88): VKClientVKApiRequest->parseResponse()
 #2 /var/www/vendor/vkcom/vk-php-sdk/src/VK/Actions/Photos.php(265): VKClientVKApiRequest->post()
 #3 /var/www/admin/model/tool/vk_product_update.php(102): VKActionsPhotos->getMarketUploadServer()
 #4 /var/www/admin/model/tool/vk_product_update.php(507): ModelToolVkProductUpdate->vkProductUpdate()
 #5 /var/www/system/engine/loader.php(297): ModelToolVkProductUpdate->checkVkUpdateData()
 #6 /var/www/system/engine/proxy.php(25): Loader->{closure}()
 #7 /var/www/admin/controlle in /var/www/vendor/vkcom/vk-php-sdk/src/VK/Client/VKApiRequest.php on line 184

@sizeg
Copy link

sizeg commented May 1, 2020

Я подебажил немного. Статус 200 через curl можно получить достаточно просто без всяких регулярок.

    public function sendRequest(string $url, array $opts) {
        $curl = curl_init($url);

        curl_setopt_array($curl, $this->initial_opts + $opts);

        $response = curl_exec($curl);

        $curl_error_code = curl_errno($curl);
        $curl_error = curl_error($curl);

        //  The last response code
        $http_code = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);

        curl_close($curl);

        if ($curl_error || $curl_error_code) {
            $error_msg = "Failed curl request. Curl error {$curl_error_code}";
            if ($curl_error) {
                $error_msg .= ": {$curl_error}";
            }

            $error_msg .= '.';

            throw new TransportRequestException($error_msg);
        }

        return $this->parseRawResponse($http_code, $response);
    }

P.S. Увидел в мастере изменения getHttpStatus не выпилили

@sizeg
Copy link

sizeg commented May 1, 2020

Подготовил PR #82

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants