Exemplo n.º 1
0
 /**
  * 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');
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }
Exemplo n.º 5
0
 /**
  * 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.");
         }
     }
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * @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;
 }
Exemplo n.º 8
0
 /**
  * @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;
 }
Exemplo n.º 9
0
 /**
  * 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;
 }
Exemplo n.º 10
0
 /**
  * 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);
 }
Exemplo n.º 11
0
 /**
  * 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]);
 }
Exemplo n.º 12
0
	/**
	 * 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];
	}
 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);
 }
Exemplo n.º 14
0
 /**
  * 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);
 }
 /**
  * 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];
 }
Exemplo n.º 16
0
 /**
  * Execute an HEAD request
  *
  * @param $uri
  * @param $options
  * @return \GuzzleHttp\Message\ResponseInterface
  */
 public function head($uri, $options)
 {
     return $this->http->head(self::API_URL . $uri, array_merge($this->httpOptions, $options));
 }