| @@ 22-46 (lines=25) @@ | ||
| 19 | * @call ( url $url, callable $resultcb ) |
|
| 20 | * @callback $resultcb ( Connection $conn, boolean $success ) |
|
| 21 | */ |
|
| 22 | public function head($url, $params) |
|
| 23 | { |
|
| 24 | if (is_callable($params)) { |
|
| 25 | $params = ['resultcb' => $params]; |
|
| 26 | } |
|
| 27 | if (!isset($params['uri']) || !isset($params['host'])) { |
|
| 28 | list($params['scheme'], $params['host'], $params['uri'], $params['port']) = static::parseUrl($url); |
|
| 29 | } |
|
| 30 | if (isset($params['connect'])) { |
|
| 31 | $dest = $params['connect']; |
|
| 32 | } elseif (isset($params['proxy']) && $params['proxy']) { |
|
| 33 | if ($params['proxy']['type'] === 'http') { |
|
| 34 | $dest = 'tcp://' . $params['proxy']['addr']; |
|
| 35 | } |
|
| 36 | } else { |
|
| 37 | $dest = 'tcp://' . $params['host'] . (isset($params['port']) ? ':' . $params['port'] : null) . ($params['scheme'] === 'https' ? '#ssl' : ''); |
|
| 38 | } |
|
| 39 | $this->getConnection($dest, function ($conn) use ($url, $params) { |
|
| 40 | if (!$conn->isConnected()) { |
|
| 41 | $params['resultcb'](false); |
|
| 42 | return; |
|
| 43 | } |
|
| 44 | $conn->head($url, $params); |
|
| 45 | }); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * Parse URL |
|
| @@ 120-144 (lines=25) @@ | ||
| 117 | * @call ( url $url, callable $resultcb ) |
|
| 118 | * @callback $resultcb ( Connection $conn, boolean $success ) |
|
| 119 | */ |
|
| 120 | public function get($url, $params) |
|
| 121 | { |
|
| 122 | if (is_callable($params)) { |
|
| 123 | $params = ['resultcb' => $params]; |
|
| 124 | } |
|
| 125 | if (!isset($params['uri']) || !isset($params['host'])) { |
|
| 126 | list($params['scheme'], $params['host'], $params['uri'], $params['port']) = static::parseUrl($url); |
|
| 127 | } |
|
| 128 | if (isset($params['connect'])) { |
|
| 129 | $dest = $params['connect']; |
|
| 130 | } elseif (isset($params['proxy']) && $params['proxy']) { |
|
| 131 | if ($params['proxy']['type'] === 'http') { |
|
| 132 | $dest = 'tcp://' . $params['proxy']['addr']; |
|
| 133 | } |
|
| 134 | } else { |
|
| 135 | $dest = 'tcp://' . $params['host'] . (isset($params['port']) ? ':' . $params['port'] : null) . ($params['scheme'] === 'https' ? '#ssl' : ''); |
|
| 136 | } |
|
| 137 | $this->getConnection($dest, function ($conn) use ($url, $params) { |
|
| 138 | if (!$conn->isConnected()) { |
|
| 139 | $params['resultcb'](false); |
|
| 140 | return; |
|
| 141 | } |
|
| 142 | $conn->get($url, $params); |
|
| 143 | }); |
|
| 144 | } |
|
| 145 | ||
| 146 | /** |
|
| 147 | * Perform a POST request |
|