Skip to content

Commit e0043bb

Browse files
committed
removed UserAgent class and try to resolve this problem automatically
1 parent 714d2cd commit e0043bb

File tree

2 files changed

+26
-52
lines changed

2 files changed

+26
-52
lines changed

src/Http/CurlDispatcher.php

+26-5
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,34 @@ public function __destruct()
7777
*/
7878
public function dispatch(Url $url)
7979
{
80-
$connection = curl_init((string) $url);
81-
curl_setopt_array($connection, $this->config);
82-
curl_setopt($connection, CURLOPT_HTTPHEADER, ['Accept: text/html']);
80+
$options = $this->config;
81+
$options[CURLOPT_HTTPHEADER] = ['Accept: text/html'];
82+
83+
$response = $this->exec($url, $options);
8384

84-
if (($useragent = UserAgent::resolve($url)) !== null) {
85-
curl_setopt($connection, CURLOPT_USERAGENT, $useragent);
85+
//Some sites returns 403 with the default user-agent
86+
if ($response->getStatusCode() === 403) {
87+
$options[CURLOPT_USERAGENT] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.95 Safari/537.36';
88+
89+
return $this->exec($url, $options);
8690
}
8791

92+
return $response;
93+
}
94+
95+
/**
96+
* Execute a curl request
97+
*
98+
* @param Url $url
99+
* @param array $options
100+
*
101+
* @return Response
102+
*/
103+
protected function exec(Url $url, array $options)
104+
{
105+
$connection = curl_init((string) $url);
106+
curl_setopt_array($connection, $options);
107+
88108
$curl = new CurlResult($connection);
89109

90110
//Get only text responses
@@ -115,6 +135,7 @@ public function dispatch(Url $url)
115135
);
116136
}
117137

138+
118139
/**
119140
* {@inheritdoc}
120141
*/

src/Http/UserAgent.php

-47
This file was deleted.

0 commit comments

Comments
 (0)