本文整理汇总了PHP中GuzzleHttp\Client::head方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::head方法的具体用法?PHP Client::head怎么用?PHP Client::head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::head方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* MailTestCase.
*/
public function __construct()
{
$this->mailcatcher = new \GuzzleHttp\Client(['base_uri' => 'http://localhost:1080']);
if ($this->mailcatcher->head('/messages')->getStatusCode() !== 200) {
throw new Exception('Install and boot up mailcatcher first. $ gem install mailcatcher && mailcatcher');
}
}
示例2: exists
/**
* Check if a gravatar exists.
*
* @param $email
*
* @return bool
*/
public function exists($email)
{
$gravatar = $this->buildURL($email, 100, 404);
try {
$this->client->head($gravatar);
return true;
} catch (RequestException $e) {
return false;
}
}
示例3: checkDependencies
/**
* @param array $dependencies
* @return array
*/
private function checkDependencies(array $dependencies, DrupalStyle $io)
{
$this->site->loadLegacyFile('/core/modules/system/system.module');
$localModules = array();
$modules = system_rebuild_module_data();
foreach ($modules as $module_id => $module) {
array_push($localModules, basename($module->subpath));
}
$checkDependencies = ['local_modules' => [], 'drupal_modules' => [], 'no_modules' => []];
foreach ($dependencies as $module) {
if (in_array($module, $localModules)) {
$checkDependencies['local_modules'][] = $module;
} else {
try {
$response = $this->httpClient->head('https://www.drupal.org/project/' . $module);
$header_link = explode(';', $response->getHeader('link'));
if (empty($header_link[0])) {
$checkDependencies['no_modules'][] = $module;
} else {
$checkDependencies['drupal_modules'][] = $module;
}
} catch (ClientException $e) {
$checkDependencies['no_modules'][] = $module;
}
}
}
return $checkDependencies;
}
示例4: head
/**
* @param string $uri
* @param array $data
* @param array $options
* @param bool $api
* @return $this;
*/
public function head($uri, array $data = [], array $options = [], $api = true)
{
$uri = $api ? $this->getServiceConfig('api_url') . $uri : $uri;
$response = $this->client->head($uri, array_merge($options, ['body' => $data]));
$this->setGuzzleResponse($response);
return $this;
}
示例5: assertFilesDownloadable
/**
* Checks that the given list of files return a 200 OK status code.
*
* @param \Behat\Gherkin\Node\TableNode $files
* The list of files that should be downloadable, relative to the base URL.
*
* @throws \Behat\Mink\Exception\ExpectationException
* Thrown when a file could not be downloaded.
*
* @Then the following files can be downloaded:
*/
public function assertFilesDownloadable(TableNode $files)
{
$client = new Client();
foreach ($files->getColumn(0) as $file) {
if ($client->head($this->locatePath($file))->getStatusCode() != 200) {
throw new ExpectationException("File {$file} could not be downloaded.");
}
}
}
示例6: linkIsValid
/**
* Before outputting custom links, it is validated to ensure that the user is not
* directed off to a broken link. If a 404 is detected, it is hidden.
*
* @param $link The proposed link
*
* @return bool
*/
private function linkIsValid($link)
{
$link = $this->docDomain . $link;
try {
$resp = $this->client->head($link);
} catch (ClientException $e) {
}
return $resp->getStatusCode() < 400;
}
示例7: getUriHeaders
/**
* @param string $uri
* @return ResponseInterface
*/
public static function getUriHeaders($uri)
{
if (!Validation::isValidLink($uri)) {
throw new InvalidUriException($uri . ' is not a valid link');
}
$httpClient = new Client();
$resource = $httpClient->head($uri, ['allow_redirects' => true, 'connect_timeout' => 2, 'timeout' => 5]);
unset($httpClient);
return $resource;
}
示例8: getUriHeaders
/**
* @param string $uri
* @return ResponseInterface
*/
public static function getUriHeaders($uri)
{
if (!self::isValidLink($uri)) {
throw new InvalidUriException($uri . ' is not a valid link');
}
$httpClient = new Client();
$resource = $httpClient->head($uri);
unset($httpClient);
return $resource;
}
示例9: examine
/**
* Checks if a string is spam or not
*
* @param mixed $data string|array
* @param array $options
* @return object
*/
public function examine(array $data, array $options = array())
{
$path = '';
$status = 0;
$meta = array();
if (isset($data['path']) && $data['path']) {
$path = ltrim($data['path'], '/');
$path = trim($path);
$meta['field'] = $data['path'];
$status = -1;
if ($this->isLink($path)) {
try {
$response = $this->client->head($path, ['exceptions' => false, 'timeout' => 10]);
$meta['code'] = $response->getStatusCode();
if ($response->getStatusCode() == 200) {
$status = 1;
}
} catch (\Exception $e) {
$meta['error'] = $e->getMessage();
}
} else {
$params = \Component::params('com_resources');
$base = $params->get('uploadpath', '/site/resources');
$base = PATH_APP . DS . trim($base, DS) . DS;
if (is_dir($base . $path)) {
$meta['error'] = 'Path is a directory';
}
if (file_exists($base . $path)) {
$status = 1;
}
}
}
$result = new Result();
$result->set(['scope_id' => $data['id'], 'status' => $status, 'notes' => json_encode($meta)]);
return $result;
}
示例10: head
/**
* Sends a HEAD request
* @param string $uri
* @param array $options Array such as
* 'headers' => [
* 'foo' => 'bar',
* ],
* 'cookies' => ['
* 'foo' => 'bar',
* ],
* 'allow_redirects' => [
* 'max' => 10, // allow at most 10 redirects.
* 'strict' => true, // use "strict" RFC compliant redirects.
* 'referer' => true, // add a Referer header
* 'protocols' => ['https'] // only allow https URLs
* ],
* 'save_to' => '/path/to/file', // save to a file or a stream
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
* @return Response
* @throws \Exception If the request could not get completed
*/
public function head($uri, $options = [])
{
$response = $this->client->head($uri, $options);
return new Response($response);
}
示例11: request
/**
* This method make simple Requests using the GuzzleClient and disalbeds redirects to get the Location Header
*
* @see Client
*
* @param string $url The URL that will get requested
* @return \Psr\Http\Message\ResponseInterface|\GuzzleHttp\Psr7\Stream
*/
protected function request($url)
{
$client = new Client();
return $client->head($url, ['allow_redirects' => false]);
}
示例12: size
/**
* Returns the video size raw or formatted to largest increment possible
*
* @param bool $raw
* @return string|int
*/
public function size( $raw = false )
{
if ( in_array( $this->domain(), array( 'youtube', 'youtu' ) ) ) {
return 0;
}
static $cache = array();
$id = $this->get( 'url' );
if ( ! isset( $cache[$id] ) ) {
$fileSize = 0;
if ( $this->exists() ) {
try {
$request = new GuzzleHttp\Client();
$header = $request->head( $id );
if ( ( $header !== false ) && ( $header->getStatusCode() == 200 ) ) {
$fileSize = (int) $header->getHeader( 'Content-Length' );
}
} catch( Exception $e ) {}
}
$cache[$id] = $fileSize;
}
if ( ! $raw ) {
return CBGroupJive::getFormattedFileSize( $cache[$id] );
}
return $cache[$id];
}
示例13: testEmitsHeadersEventForHeadRequest
public function testEmitsHeadersEventForHeadRequest()
{
Server::enqueue(["HTTP/1.1 200 OK\r\nContent-Length: 2\r\n\r\nOK"]);
$ee = null;
$client = new Client(['adapter' => new MultiAdapter(new MessageFactory())]);
$client->head(Server::$url, ['events' => ['headers' => function (HeadersEvent $e) use(&$ee) {
$ee = $e;
}]]);
$this->assertInstanceOf('GuzzleHttp\\Event\\HeadersEvent', $ee);
}
示例14: head
/**
* Sends a HEAD request
*
* @param string $uri
* @param array $options Array such as
* 'headers' => [
* 'foo' => 'bar',
* ],
* 'cookies' => ['
* 'foo' => 'bar',
* ],
* 'allow_redirects' => [
* 'max' => 10, // allow at most 10 redirects.
* 'strict' => true, // use "strict" RFC compliant redirects.
* 'referer' => true, // add a Referer header
* 'protocols' => ['https'] // only allow https URLs
* ],
* 'save_to' => '/path/to/file', // save to a file or a stream
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
* @return Response
* @throws \Exception If the request could not get completed
*/
public function head($uri, $options = [])
{
$this->setDefaultOptions();
$response = $this->client->head($uri, $options);
return new Response($response);
}
示例15: getMimetype
/**
* Get the mimetype of a file.
*
* @param string $path
*
* @return array|false
*/
public function getMimetype($path)
{
$response = $this->httpClient->head($this->applyPathPrefix($path), ['headers' => ['X-Akamai-ACS-Action' => $this->getAcsActionHeaderValue('download')]]);
$mimetype = $response->getHeader('Content-Type')[0];
return ['mimetype' => $mimetype];
}