本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::hasHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::hasHeader方法的具体用法?PHP RequestInterface::hasHeader怎么用?PHP RequestInterface::hasHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::hasHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
/**
* {@inheritdoc}
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Add a date header if one is not set
if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
$request->setHeader('Date', gmdate(DateFormat::RFC2822));
}
$stringToSign = (string) $request->getHeader('Date') ?: (string) $request->getHeader('x-amz-date');
$request->getParams()->set('aws.string_to_sign', $stringToSign);
$request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
}
示例2: signRequest
/**
* {@inheritdoc}
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Add the security token header if one is being used by the credentials
if ($token = $credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $token);
}
// Add a date header if one is not set
if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
$request->setHeader('Date', gmdate(DateFormat::RFC2822));
}
$stringToSign = $this->createCanonicalizedString($request);
$request->getParams()->set('aws.string_to_sign', $stringToSign);
$request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
}
示例3: after
public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;
if (isset($this->data[$command])) {
$xml = $this->finishDocument($this->data[$command]);
unset($this->data[$command]);
} else {
$operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xmlWriter = $this->createRootElement($operation);
$xml = $this->finishDocument($xmlWriter);
}
}
if ($xml) {
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
$request->setBody($xml);
}
}
示例4: signRequest
/**
* Always add a x-amz-content-sha-256 for data integrity.
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody() && !$request->hasHeader('x-amz-content-sha256')) {
$request->setHeader('X-Amz-Content-Sha256', $this->getPresignedPayload($request));
}
parent::signRequest($request, $credentials);
}
示例5: signRequest
/**
* Always add a x-amz-content-sha-256 for data integrity.
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
if (!$request->hasHeader('x-amz-content-sha256')) {
$request->setHeader('x-amz-content-sha256', $this->getPayload($request));
}
parent::signRequest($request, $credentials);
}
示例6: after
public function after(CommandInterface $command, RequestInterface $request)
{
if (isset($this->data[$command])) {
if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->jsonContentType);
}
$request->setBody(json_encode($this->data[$command]));
unset($this->data[$command]);
}
}
示例7: signRequest
/**
* {@inheritdoc}
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Add a date header if one is not set
if (!$request->hasHeader('date') && !$request->hasHeader('x-amz-date')) {
$request->setHeader('Date', $this->getDateTime(DateFormat::RFC1123));
}
// Add the security token if one is present
if ($credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
}
// Determine the string to sign
$stringToSign = $request->getHeader('Date', true) ?: $request->getHeader('x-amz-date', true);
$request->getParams()->set('aws.string_to_sign', $stringToSign);
// Calculate the signature
$signature = base64_encode(hash_hmac('sha256', $stringToSign, $credentials->getSecretKey(), true));
// Add the authorization header to the request
$headerFormat = 'AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=HmacSHA256,Signature=%s';
$request->setHeader('X-Amzn-Authorization', sprintf($headerFormat, $credentials->getAccessKeyId(), $signature));
}
示例8: canCacheRequest
public function canCacheRequest(RequestInterface $request)
{
if ($request->getMethod() != RequestInterface::GET && $request->getMethod() != RequestInterface::HEAD) {
return false;
}
if ($request->hasHeader('Cache-Control') && $request->getHeader('Cache-Control')->hasDirective('no-store')) {
return false;
}
return true;
}
示例9: after
/**
* {@inheritdoc}
*/
public function after(CommandInterface $command, RequestInterface $request)
{
if (isset($this->data[$command])) {
$request->setBody($this->data[$command]->asXML());
unset($this->data[$command]);
// Don't overwrite the Content-Type if one is set
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
}
}
示例10: addDefaultContextOptions
protected function addDefaultContextOptions(RequestInterface $request)
{
$this->setContextValue('http', 'method', $request->getMethod());
$headers = $request->getHeaderLines();
if (!$request->hasHeader('Connection')) {
$headers[] = 'Connection: close';
}
$this->setContextValue('http', 'header', $headers);
$this->setContextValue('http', 'protocol_version', $request->getProtocolVersion());
$this->setContextValue('http', 'ignore_errors', true);
}
示例11: after
/**
* {@inheritdoc}
*/
public function after(CommandInterface $command, RequestInterface $request)
{
if (isset($this->data[$command])) {
$json = $this->data[$command];
unset($this->data[$command]);
$request->setBody(json_encode($json));
// Don't overwrite the Content-Type if one is set
if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->jsonContentType);
}
}
}
示例12: after
public function after(CommandInterface $command, RequestInterface $request)
{
$xml = null;
// If data was found that needs to be serialized, then do so
if (isset($this->data[$command])) {
$xml = $this->data[$command]->asXML();
unset($this->data[$command]);
} else {
// Check if XML should always be sent for the command
$operation = $command->getOperation();
if ($operation->getData('xmlAllowEmpty')) {
$xml = $this->createRootElement($operation)->asXML();
}
}
if ($xml) {
$request->setBody($xml);
// Don't overwrite the Content-Type if one is set
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
}
}
示例13: beforeSend
/**
* Prepare for sending
*
* @param RequestInterface $request Request to prepare
* @throws \Exception on error preparing the request
*/
protected function beforeSend(RequestInterface $request)
{
try {
// Fix Content-Length and Transfer-Encoding collisions
if ($request->hasHeader('Transfer-Encoding') && $request->hasHeader('Content-Length')) {
$request->removeHeader('Transfer-Encoding');
}
$request->setState(RequestInterface::STATE_TRANSFER);
$request->dispatch('request.before_send', array('request' => $request));
if ($request->getState() != RequestInterface::STATE_TRANSFER) {
// Requests might decide they don't need to be sent just before transfer (e.g. CachePlugin)
$this->remove($request);
if ($request->getState() == RequestInterface::STATE_COMPLETE) {
$this->successful[] = $request;
}
} else {
// Add the request curl handle to the multi handle
$this->checkCurlResult(curl_multi_add_handle($this->multiHandle, $this->createCurlHandle($request)->getHandle()));
}
} catch (\Exception $e) {
// Queue the exception to be thrown when sent
$this->removeErroredRequest($request, $e);
}
}
示例14: hasHeader
/**
* @param string $name
* @return bool
*/
public function hasHeader($name)
{
return $this->request->hasHeader($name);
}
示例15: visit_headers
protected function visit_headers(RequestInterface $request, $value, $flags)
{
if (!is_array($value)) {
throw new InvalidArgumentException('headers value must be an array');
}
if ($flags & self::OPTIONS_AS_DEFAULTS) {
foreach ($value as $key => $header) {
if (!$request->hasHeader($key)) {
$request->setHeader($key, $header);
}
}
} else {
$request->addHeaders($value);
}
}