+
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/CurlAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,38 @@ public function delete(string $endpoint, array $headers = [], bool $header_out =
return $this->getQueryResponse($curl);
}

/**
* Checks for CURLOPT_HTTP_VERSION to specify
* HTTP1.0, HTTP1.1, or HTTP2.0 request.
* Defaults to HTTP1.1.
* @return int
*/
protected function getHttpVersion(): int
{
$http_version = CURL_HTTP_VERSION_1_1;
$curlopt = getenv('CURLOPT_HTTP_VERSION');
switch ($curlopt) {
case false:
break;
case 'CURL_HTTP_VERSION_1_0':
$http_version = constant($curlopt);
break;
case 'CURL_HTTP_VERSION_1_1':
$http_version = constant($curlopt);
break;
case 'CURL_HTTP_VERSION_2':
$http_version = constant($curlopt);
break;
case 'CURL_HTTP_VERSION_2_0':
$http_version = constant($curlopt);
break;
default:
echo "Unknown HTTP version $curlopt, continuing anyway";
$http_version = 0;
}
return $http_version;
}

/**
* Execs curl and saves information about the request.
* Returns an array with two items: 'code' and 'body'.
Expand All @@ -90,6 +122,7 @@ public function delete(string $endpoint, array $headers = [], bool $header_out =
*/
protected function getQueryResponse($curl): array
{
curl_setopt($curl, CURLOPT_HTTP_VERSION, $this->getHttpVersion());
$response = curl_exec($curl);
$this->last_request_info = curl_getinfo($curl);
$response_code = $this->last_request_info['http_code'];
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载