本文整理汇总了PHP中Guzzle\Http\Message\RequestInterface::setHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::setHeader方法的具体用法?PHP RequestInterface::setHeader怎么用?PHP RequestInterface::setHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Ensure that the signable query string parameters are sorted
sort($this->signableQueryString);
// Add the security token header if one is being used by the credentials
if ($token = $credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $token);
}
$request->removeHeader('x-amz-date');
$request->setHeader('Date', gmdate(\DateTime::RFC2822));
$stringToSign = $this->createCanonicalizedString($request);
$request->getParams()->set('aws.string_to_sign', $stringToSign);
$request->setHeader('Authorization', 'AWS ' . $credentials->getAccessKeyId() . ':' . $this->signString($stringToSign, $credentials));
// COMMONLOG(DEBUG, "send header:%s",$request->getRawHeaders());
// if(self::$isFile)
// {
// if(self::$filePath)
// COMMONLOG(DEBUG, "souce file:%s",self::$filePath);
// }
// else
// {
// if(get_class($request) === 'Guzzle\Http\Message\EntityEnclosingRequest' && get_class($request->getBody()) === 'Guzzle\Http\EntityBody' && $request->getBody()->getContentLength() != 0)
// {
// COMMONLOG(DEBUG, "send msg:%s",$request->getBody());
// }
// }
}
示例2: signRequest
/**
* {@inheritdoc}
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
// Refresh the cached timestamp
$this->getTimestamp(true);
// Add default headers
$request->setHeader('x-amz-date', $this->getDateTime(DateFormat::RFC1123));
// Add the security token if one is present
if ($credentials->getSecurityToken()) {
$request->setHeader('x-amz-security-token', $credentials->getSecurityToken());
}
// Grab the path and ensure that it is absolute
$path = '/' . ltrim($request->getUrl(true)->normalizePath()->getPath(), '/');
// Begin building the string to sign
$sign = $request->getMethod() . "\n" . "{$path}\n" . $this->getCanonicalizedQueryString($request) . "\n";
// Get all of the headers that must be signed (host and x-amz-*)
$headers = $this->getHeadersToSign($request);
foreach ($headers as $key => $value) {
$sign .= $key . ':' . $value . "\n";
}
$sign .= "\n";
// Add the body of the request if a body is present
if ($request instanceof EntityEnclosingRequestInterface) {
$sign .= (string) $request->getBody();
}
// Add the string to sign to the request for debugging purposes
$request->getParams()->set('aws.string_to_sign', $sign);
$signature = base64_encode(hash_hmac('sha256', hash('sha256', $sign, true), $credentials->getSecretKey(), true));
// Add the authorization header to the request
$request->setHeader('x-amzn-authorization', sprintf('AWS3 AWSAccessKeyId=%s,Algorithm=HmacSHA256,SignedHeaders=%s,Signature=%s', $credentials->getAccessKeyId(), implode(';', array_keys($headers)), $signature));
}
示例3: signRequest
/**
* @param RequestInterface|EntityEnclosingRequestInterface $request
* @param Credentials $credentials
*/
public function signRequest($request, $credentials)
{
$request->setHeader('X-HMB-Signature-Method', self::DEFAULT_METHOD);
$request->setHeader('X-HMB-Signature-Version', self::DEFAULT_SIGN_VERSION);
$request->setHeader('X-HMB-TimeStamp', time());
$contentMd5 = $request instanceof EntityEnclosingRequestInterface ? md5($request->getBody()) : '';
if ($contentMd5) {
$request->setHeader('Content-MD5', $contentMd5);
}
$sign = array();
$sign[] = strtoupper($request->getMethod());
$sign[] = $request->getHost();
if ($request->getHeader('Content-MD5')) {
$sign[] = $request->getHeader('Content-MD5');
}
if ($request->getHeader('Content-Type')) {
$sign[] = $request->getHeader('Content-Type');
}
$sign[] = $request->getHeader('X-HMB-Signature-Method');
$sign[] = $request->getHeader('X-HMB-Signature-Version');
$sign[] = $request->getHeader('X-HMB-TimeStamp');
if ($request->getHeader('X-HMB-User-Session-Token')) {
$sign[] = $request->getHeader('X-HMB-User-Session-Token');
}
$sign[] = $request->getQuery(true) ? $request->getPath() . '?' . $request->getQuery(true) : $request->getPath();
$signature = base64_encode(hash_hmac(strtolower($request->getHeader('X-HMB-Signature-Method')), implode("\n", $sign), $credentials->getSecret()));
$request->setHeader('Authorization', sprintf('%s %s:%s', self::AUTHORIZATION_SCHME, $credentials->getKey(), $signature));
}
示例4: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
if ($request instanceof EntityEnclosingRequestInterface && $request->getBody()) {
$request->setHeader('X-Amz-Content-Sha256', EntityBody::getHash($request->getBody(), 'sha256'));
} else {
$request->setHeader('X-Amz-Content-Sha256', hash('sha256', ''));
}
parent::signRequest($request, $credentials);
}
示例5: 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));
}
示例6: 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));
}
示例7: 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);
}
}
示例8: 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);
}
示例9: setHeaders
/**
* @param RequestInterface $request
*
* @return RequestInterface
*/
private function setHeaders(RequestInterface $request)
{
foreach ($this->headers as $name => $value) {
$request->setHeader($name, $value);
}
return $request;
}
示例10: 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);
}
示例11: 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]);
}
}
示例12: 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));
}
示例13: addPrefixedHeaders
/**
* Add a prefixed array of headers to the request
*
* @param RequestInterface $request Request to update
* @param Parameter $param Parameter object
* @param array $value Header array to add
*
* @throws InvalidArgumentException
*/
protected function addPrefixedHeaders(RequestInterface $request, Parameter $param, $value)
{
if (!is_array($value)) {
throw new InvalidArgumentException('An array of mapped headers expected, but received a single value');
}
$prefix = $param->getSentAs();
foreach ($value as $headerName => $headerValue) {
$request->setHeader($prefix . $headerName, $headerValue);
}
}
示例14: after
/**
* {@inheritdoc}
*/
public function after(CommandInterface $command, RequestInterface $request)
{
if (isset($this->data[$command])) {
$xml = $this->data[$command];
unset($this->data[$command]);
$request->setBody($xml->asXML());
if ($this->contentType) {
$request->setHeader('Content-Type', $this->contentType);
}
}
}
示例15: 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))->removeHeader('Expect');
if ($this->jsonContentType) {
$request->setHeader('Content-Type', $this->jsonContentType);
}
}
}