Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ad213d7

Browse files
committed
Updated script
1 parent 2ad873b commit ad213d7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

‎example.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
$curl = new Curl(array(
55
'timeout' => 30, // time limit for request
66
'strict_mode' => false, // whether CURLOPT_FAILONERROR or not
7-
'max_redirects' => 10 // number of redirections to follow
7+
'max_redirects' => 10, // number of redirections to follow
8+
'http_version' => '1.1' // HTTP version (1.1, 1.0)
89
));
910

1011

‎lib/Curl.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class Curl
2323
protected $strict_mode = false;
2424
protected $max_redirects = 10;
2525

26+
protected $http_version = NULL;
27+
protected $http_versions = array(
28+
'1.0' => CURL_HTTP_VERSION_1_0,
29+
'1.1' => CURL_HTTP_VERSION_1_1
30+
);
31+
2632
/**
2733
* Initialize class
2834
* @param array $config
@@ -292,7 +298,11 @@ public function execute($url = ''){
292298
$this->options[CURLOPT_MAXREDIRS] = $this->max_redirects;
293299
}
294300

295-
empty($this->headers) or $this->options[CURLOPT_HTTPHEADER] = $this->headers;
301+
(isset($this->options[CURLOPT_HTTPHEADER]) or empty($this->headers))
302+
or $this->options[CURLOPT_HTTPHEADER] = $this->headers;
303+
304+
(isset($this->options[CURLOPT_HTTP_VERSION]) or empty($this->http_version))
305+
or $this->options[CURLOPT_HTTP_VERSION] = $this->http_version;
296306

297307
if($this->request = curl_init($this->url) and is_resource($this->request)){
298308
$set_options = curl_setopt_array($this->request, $this->options);
@@ -384,6 +394,9 @@ protected function _initialize($config){
384394
isset($config['timeout']) and $this->timeout = $config['timeout'];
385395
isset($config['strict_mode']) and $this->strict_mode = (bool) $config['strict_mode'];
386396
isset($config['max_redirects']) and $this->max_redirects = (int) $config['max_redirects'];
397+
398+
(isset($config['http_version']) and isset($this->http_versions[$config['http_version']]))
399+
and $this->http_version = $this->http_versions[$config['http_version']];
387400
}
388401
}
389402

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /