You are here

public function HttpClientTrait::requestTryHeadLookingForHeader in Remote Stream Wrapper 8

Perform a HEAD/GET request looking for a specific header.

If the header was found in the HEAD request, then the HEAD response is returned. Otherwise the GET request response is returned (without checking if the header was found).

Parameters

string $uri:

string $header: Case-insensitive header field name.

array $options:

Return value

\Psr\Http\Message\ResponseInterface The HTTP response object.

Throws

\GuzzleHttp\Exception\GuzzleException

2 calls to HttpClientTrait::requestTryHeadLookingForHeader()
HttpMimeTypeGuesser::guess in src/File/MimeType/HttpMimeTypeGuesser.php
Guesses the mime type of the file with the given path.
HttpStreamWrapper::stream_stat in src/StreamWrapper/HttpStreamWrapper.php

File

src/HttpClientTrait.php, line 60

Class

HttpClientTrait
Trait to help reuse HTTP client logic.

Namespace

Drupal\remote_stream_wrapper

Code

public function requestTryHeadLookingForHeader($uri, $header, array $options = []) {
  try {
    $response = $this
      ->getHttpClient()
      ->request('HEAD', $uri, $options);
    if ($response
      ->hasHeader($header)) {
      return $response;
    }
  } catch (ClientException $exception) {

    // Do nothing, try a GET request instead.
  } catch (ServerException $exception) {

    // Do nothing, try a GET request instead.
  }
  return $this
    ->getHttpClient()
    ->request('GET', $uri, $options);
}