protected function _checkDownloads() { $this->log('start to check downloads'); $failedChecks = array(); foreach ($this->_downloadList as $downloadId => $url) { try { $this->log('check %s', $url); $response = \Requests::head($url); if (!$response->success) { $failedChecks[$downloadId] = 'unknown reason'; } } catch (\Exception $e) { $failedChecks[$downloadId] = $e->getMessage(); } } $message = new \SAP\Daemon\Message\Download\CheckResult(array('failedChecks' => $failedChecks)); $this->log('send message to worker'); $zmsg = new \ZMQ\Zmsg($this->_socketToWorker); $zmsg->body_set(serialize($message)); $zmsg->send(); $this->log('finished downloads-check'); return $failedChecks; }
public function testHEAD() { $request = Requests::head(httpbin('/get'), array(), $this->getOptions()); $this->assertEquals(200, $request->status_code); $this->assertEquals('', $request->body); }
/** * Test that the transport supports Server Name Indication with HTTPS * * feelingrestful.com (owned by hmn.md and used with permission) points to * CloudFlare, and will fail if SNI isn't sent. */ public function testSNISupport() { if ($this->skip_https) { $this->markTestSkipped('SSL support is not available.'); return; } $request = Requests::head('https://feelingrestful.com/', array(), $this->getOptions()); $this->assertEquals(200, $request->status_code); }
/** * Check if a media id is valid. * * @param string $id Id to check against the oembed stream. * * @return boolean TRUE if id is valid, FALSE otherwise. Throws errors * on invalid ids. */ protected function validId($id) { $endpoint = $this->config->get('endpoint', ''); $endpoint = $this->format($endpoint, ['{:id}' => $id]); if (!$id || !$endpoint) { return false; } $response = \Requests::head($endpoint); // If a head request fails, try to send a get request if ($response->status_code != 200) { $response = \Requests::get($endpoint); } if ($response->status_code == 401) { throw new \Exception('Embedding has been disabled for this media.'); } elseif ($response->status_code == 404) { throw new \Exception('The media ID was not found.'); } elseif ($response->status_code == 501) { throw new \Exception('Media informations can not be retrieved.'); } elseif ($response->status_code != 200) { throw new \Exception('The media ID is invalid or the media was deleted.'); } elseif (!$response->success) { $response->throw_for_status(); } return true; }