File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change 4
4
5
5
class Curl
6
6
{
7
- const USER_AGENT = 'PHP-Curl-Class/ 2.1.0 (+https://github.com/php-curl-class/php-curl-class) ' ;
7
+ const VERSION = '2.1.0 ' ;
8
8
9
9
private $ cookies = array ();
10
10
private $ headers = array ();
@@ -43,7 +43,7 @@ public function __construct()
43
43
}
44
44
45
45
$ this ->curl = curl_init ();
46
- $ this ->setUserAgent ( self :: USER_AGENT );
46
+ $ this ->setDefaultUserAgent ( );
47
47
$ this ->setOpt (CURLINFO_HEADER_OUT , true );
48
48
$ this ->setOpt (CURLOPT_HEADER , true );
49
49
$ this ->setOpt (CURLOPT_RETURNTRANSFER , true );
@@ -169,6 +169,15 @@ public function unsetHeader($key)
169
169
unset($ this ->headers [$ key ]);
170
170
}
171
171
172
+ public function setDefaultUserAgent ()
173
+ {
174
+ $ user_agent = 'PHP-Curl-Class/ ' . self ::VERSION . ' (+https://github.com/php-curl-class/php-curl-class) ' ;
175
+ $ user_agent .= ' PHP/ ' . PHP_VERSION ;
176
+ $ curl_version = curl_version ();
177
+ $ user_agent .= ' curl/ ' . $ curl_version ['version ' ];
178
+ $ this ->setUserAgent ($ user_agent );
179
+ }
180
+
172
181
public function setUserAgent ($ user_agent )
173
182
{
174
183
$ this ->setOpt (CURLOPT_USERAGENT , $ user_agent );
Original file line number Diff line number Diff line change @@ -73,11 +73,14 @@ function assertions($array, $count = 1)
73
73
74
74
public function testUserAgent ()
75
75
{
76
+ $ php_version = 'PHP\/ ' . PHP_VERSION ;
77
+ $ curl_version = curl_version ();
78
+ $ curl_version = 'curl\/ ' . $ curl_version ['version ' ];
79
+
76
80
$ test = new Test ();
77
- $ test ->curl ->setUserAgent (Curl::USER_AGENT );
78
- $ this ->assertTrue ($ test ->server ('server ' , 'GET ' , array (
79
- 'key ' => 'HTTP_USER_AGENT ' ,
80
- )) === Curl::USER_AGENT );
81
+ $ user_agent = $ test ->server ('server ' , 'GET ' , array ('key ' => 'HTTP_USER_AGENT ' ));
82
+ $ this ->assertRegExp ('/ ' . $ php_version . '/ ' , $ user_agent );
83
+ $ this ->assertRegExp ('/ ' . $ curl_version . '/ ' , $ user_agent );
81
84
}
82
85
83
86
public function testGet ()
You can’t perform that action at this time.
0 commit comments