本文整理汇总了PHP中Psr\Http\Message\RequestInterface::hasHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::hasHeader方法的具体用法?PHP RequestInterface::hasHeader怎么用?PHP RequestInterface::hasHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Psr\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::hasHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getRequestId
/**
* @return string
*/
public function getRequestId()
{
if ($this->request->hasHeader($this->headerName)) {
return $this->request->getHeader($this->headerName);
}
return $this->fallback->getRequestId();
}
示例2: getHeader
/**
* {@inheritdoc}
*/
public function getHeader($header)
{
if (!$this->request->hasHeader($header)) {
if (strtolower($header) === 'host' && ($this->request->getUri() && $this->request->getUri()->getHost())) {
return array($this->getHostFromUri());
}
return array();
}
return $this->request->getHeader($header);
}
示例3: theSentRequestShouldContainAnHeader
/**
* @Then the sent request should contain an :header header
*/
public function theSentRequestShouldContainAnHeader($header)
{
if (null === $this->request) {
throw new \RuntimeException('No request found, maybe no registered hook, right?');
} else {
if (!$this->request->hasHeader($header)) {
throw new \RuntimeException('Header not found in request');
}
}
}
示例4: addExpectHeader
private function addExpectHeader(RequestInterface $request, array $options, array &$modify)
{
// Determine if the Expect header should be used
if ($request->hasHeader('Expect')) {
return;
}
$expect = isset($options['expect']) ? $options['expect'] : null;
// Return if disabled or if you're not using HTTP/1.1 or HTTP/2.0
if ($expect === false || $request->getProtocolVersion() < 1.1) {
return;
}
// The expect header is unconditionally enabled
if ($expect === true) {
$modify['set_headers']['Expect'] = '100-Continue';
return;
}
// By default, send the expect header when the payload is > 1mb
if ($expect === null) {
$expect = 1048576;
}
// Always add if the body cannot be rewound, the size cannot be
// determined, or the size is greater than the cutoff threshold
$body = $request->getBody();
$size = $body->getSize();
if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
$modify['set_headers']['Expect'] = '100-Continue';
}
}
示例5: match
/**
* @param RequestInterface $request
* @return MatchResultInterface
*/
public function match(RequestInterface $request)
{
if ($request->hasHeader('X-GitHub-Event')) {
return new MatchResult(true, $this->getNotificationEvent($request));
}
return new UnmatchedResult();
}
示例6: presign
/**
* Always add a x-amz-content-sha-256 for data integrity.
*/
public function presign(RequestInterface $request, CredentialsInterface $credentials, $expires)
{
if (!$request->hasHeader('x-amz-content-sha256')) {
$request = $request->withHeader('X-Amz-Content-Sha256', $this->getPresignedPayload($request));
}
return parent::presign($request, $credentials, $expires);
}
示例7: handleRequest
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
foreach ($this->headers as $header) {
if ($request->hasHeader($header)) {
$request = $request->withoutHeader($header);
}
}
return $next($request);
}
示例8: __invoke
public function __invoke(CommandInterface $command, RequestInterface $request)
{
$name = $command->getName();
$body = $request->getBody();
if (!$request->hasHeader('Content-MD5') && $body->getSize() && in_array($name, self::$requireMd5)) {
$request = $request->withHeader('Content-MD5', base64_encode(Psr7\hash($body, 'md5', true)));
}
$next = $this->nextHandler;
return $next($command, $request);
}
示例9: normalizeCustomHeaders
/**
* Normalizes the custom headers for signing.
*
* @return string[]
* An array of normalized headers.
*/
protected function normalizeCustomHeaders()
{
$headers = [];
// The spec requires that headers are sorted by header name.
sort($this->headers);
foreach ($this->headers as $header) {
if ($this->request->hasHeader($header)) {
$headers[] = strtolower($header) . ':' . $this->request->getHeaderLine($header);
}
}
return $headers;
}
示例10: signRequest
/**
* Signs the request, adds the HMAC hash to the authorization header.
*
* @param \Psr\Http\Message\RequestInterface $request
*
* @return \Psr\Http\Message\RequestInterface
*/
public function signRequest(RequestInterface $request)
{
if (!$request->hasHeader('Date')) {
$time = new \DateTime();
$time->setTimezone(new \DateTimeZone('GMT'));
$request = $request->withHeader('Date', $time->format('D, d M Y H:i:s \\G\\M\\T'));
}
if (!$request->hasHeader('Content-Type')) {
$request = $request->withHeader('Content-Type', $this->defaultContentType);
}
$authorization = $this->requestSigner->getAuthorization(new RequestWrapper($request), $this->id, $this->secretKey);
return $request->withHeader('Authorization', $authorization);
}
示例11: forgeServerGlobal
/**
* Take a request and update the $_SERVER global to match
*
* @param RequestInterface $request
*/
private function forgeServerGlobal(RequestInterface $request)
{
$_SERVER['REQUEST_URI'] = $request->getUri()->getPath();
$_SERVER['REQUEST_METHOD'] = $request->getMethod();
$_SERVER['QUERY_STRING'] = $request->getUri()->getQuery();
if ($request->hasHeader('Content-Type')) {
$_SERVER['CONTENT_TYPE'] = $request->getHeaderLine('Content-Type');
}
if ($request->hasHeader('Referer')) {
$_SERVER['HTTP_REFERER'] = $request->getHeaderLine('Referer');
}
if ($request->hasHeader('X-Requested-with')) {
$_SERVER['HTTP_X_REQUESTED_WITH'] = $request->getHeaderLine('X-Requested-With');
}
if ($request->hasHeader('User-Agent')) {
$_SERVER['HTTP_USER_AGENT'] = $request->getHeaderLine('User-Agent');
}
if ($request->hasHeader('X-Forwarded-For')) {
$_SERVER['HTTP_X_FORWARDED_FOR'] = $request->getHeaderLine('X-Forwarded-For');
}
return $this;
}
示例12: handleRequest
/**
* {@inheritdoc}
*/
public function handleRequest(RequestInterface $request, callable $next, callable $first)
{
if (!$request->hasHeader('Content-Length')) {
$stream = $request->getBody();
// Cannot determine the size so we use a chunk stream
if (null === $stream->getSize()) {
$stream = new ChunkStream($stream);
$request = $request->withBody($stream);
} else {
$request = $request->withHeader('Content-Length', $stream->getSize());
}
}
return $next($request);
}
示例13: __invoke
public function __invoke(CommandInterface $command, RequestInterface $request)
{
$next = $this->nextHandler;
$name = $command->getName();
$body = $request->getBody();
if (in_array($name, self::$md5) && !$request->hasHeader('Content-MD5')) {
// Set the content MD5 header for operations that require it.
$request = $request->withHeader('Content-MD5', base64_encode(Psr7\hash($body, 'md5', true)));
} elseif (in_array($name, self::$sha256) && $command['ContentSHA256']) {
// Set the content hash header if provided in the parameters.
$request = $request->withHeader('X-Amz-Content-Sha256', $command['ContentSHA256']);
}
return $next($command, $request);
}
示例14: getPayload
protected function getPayload(RequestInterface $request)
{
// Calculate the request signature payload
if ($request->hasHeader('X-Amz-Content-Sha256')) {
// Handle streaming operations (e.g. Glacier.UploadArchive)
return $request->getHeaderLine('X-Amz-Content-Sha256');
}
if (!$request->getBody()->isSeekable()) {
throw new CouldNotCreateChecksumException('sha256');
}
try {
return Psr7\hash($request->getBody(), 'sha256');
} catch (\Exception $e) {
throw new CouldNotCreateChecksumException('sha256', $e);
}
}
示例15: createFromRequest
/**
* {@inheritDoc}
*/
public static function createFromRequest(RequestInterface $request)
{
if (!$request->hasHeader('Authorization')) {
throw new MalformedRequestException('Authorization header is required.', null, 0, $request);
}
$header = $request->getHeaderLine('Authorization');
$id_match = preg_match('/.*id="(.*?)"/', $header, $id_matches);
$realm_match = preg_match('/.*realm="(.*?)"/', $header, $realm_matches);
$nonce_match = preg_match('/.*nonce="(.*?)"/', $header, $nonce_matches);
$version_match = preg_match('/.*version="(.*?)"/', $header, $version_matches);
$signature_match = preg_match('/.*signature="(.*?)"/', $header, $signature_matches);
$headers_match = preg_match('/.*headers="(.*?)"/', $header, $headers_matches);
if (!$id_match || !$realm_match || !$nonce_match || !$version_match || !$signature_match) {
throw new MalformedRequestException('Authorization header requires a realm, id, version, nonce and a signature.', null, 0, $request);
}
$customHeaders = !empty($headers_matches[1]) ? explode('%3B', $headers_matches[1]) : [];
return new static(rawurldecode($realm_matches[1]), $id_matches[1], $nonce_matches[1], $version_matches[1], $customHeaders, $signature_matches[1]);
}