Skip to content

Commit ba04b27

Browse files
committed
add url into response
1 parent f131d5e commit ba04b27

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/Curl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ public function exec()
8989
$responseStr = curl_exec($this->handle);
9090
}
9191

92-
$id = spl_object_hash($this);
9392
$errno = curl_errno($this->handle);
9493
$errstr = curl_error($this->handle);//Fix: curl_errno() always return 0 when fail
95-
$this->response = $this->toResponse($id, $responseStr, $errno, $errstr);
94+
$url = curl_getinfo($this->handle, CURLINFO_EFFECTIVE_URL);
95+
$this->response = $this->toResponse($url, $responseStr, $errno, $errstr);
9696
return $this->response;
9797
}
9898

src/Response.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Response
66
{
7-
protected $id;
7+
protected $url;
88
protected $httpCode;
99
protected $headers = [];
1010
protected $body = '';
@@ -15,15 +15,20 @@ class Response
1515
*/
1616
protected $error = [];
1717

18-
public function __construct($id = null, $httpCode = 0, $body = '', array $headers = [], array $error = [])
18+
public function __construct($url = null, $httpCode = 0, $body = '', array $headers = [], array $error = [])
1919
{
20-
$this->id = $id ?: uniqid('', true);
20+
$this->url = $url;
2121
$this->httpCode = $httpCode;
2222
$this->headers = array_change_key_case($headers, CASE_LOWER);
2323
$this->body = $body;
2424
$this->error = $error;
2525
}
2626

27+
public function getUrl()
28+
{
29+
return $this->url;
30+
}
31+
2732
public function getHttpCode()
2833
{
2934
return $this->httpCode;

src/ResponseParser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public function parse($str)
1717
return [$headers, $body];
1818
}
1919

20-
public function toResponse($id, $responseStr, $errno, $errstr)
20+
public function toResponse($url, $responseStr, $errno, $errstr)
2121
{
2222
$httpCode = 0;
2323
$error = [];
@@ -29,6 +29,6 @@ public function toResponse($id, $responseStr, $errno, $errstr)
2929
$httpCode = curl_getinfo($this->handle, CURLINFO_HTTP_CODE);
3030
list($headers, $body) = $this->parse($responseStr);
3131
}
32-
return new Response($id, $httpCode, $body, $headers, $error);
32+
return new Response($url, $httpCode, $body, $headers, $error);
3333
}
3434
}

0 commit comments

Comments
 (0)