本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::getHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeader方法的具体用法?PHP RequestInterface::getHeader怎么用?PHP RequestInterface::getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHeader方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fromIncomingResponse
/**
* @param RequestInterface $originalRequest
* @param ResponseInterface|null $response
*
* @return Span
*/
public function fromIncomingResponse(RequestInterface $originalRequest, ResponseInterface $response = null)
{
$span = $originalRequest->getHeader('X-B3-SpanId');
$trace = $originalRequest->getHeader('X-B3-TraceId');
if (empty($span) || empty($trace)) {
throw new \InvalidArgumentException('Unable to find the original request properties');
}
return new Span(Identifier::fromString($span), $this->getName($originalRequest), Identifier::fromString($trace), [new Annotation(Annotation::CLIENT_RECEIVE, $this->clock->microseconds(), $this->endpointResolver->resolve())], [new BinaryAnnotation('http.status', $response !== null ? $response->getStatusCode() : 0, BinaryAnnotation::TYPE_INTEGER_16)]);
}
示例2: createCanonicalizedString
private function createCanonicalizedString(RequestInterface $request, $expires = null)
{
$buffer = $request->getMethod() . "\n";
// Add the interesting headers
foreach ($this->signableHeaders as $header) {
$buffer .= $request->getHeader($header) . "\n";
}
$date = $expires ?: $request->getHeader('date');
$buffer .= "{$date}\n" . $this->createCanonicalizedAmzHeaders($request) . $this->createCanonicalizedResource($request);
return $buffer;
}
示例3: applyBody
private function applyBody(RequestInterface $request, array &$options)
{
if ($request->hasHeader('Content-Length')) {
$size = (int) $request->getHeader('Content-Length');
} else {
$size = null;
}
$request->getBody()->seek(0);
// You can send the body as a string using curl's CURLOPT_POSTFIELDS
if ($size !== null && $size < 32768 || isset($request->getConfig()['curl']['body_as_string'])) {
$options[CURLOPT_POSTFIELDS] = $request->getBody()->getContents();
// Don't duplicate the Content-Length header
$this->removeHeader('Content-Length', $options);
$this->removeHeader('Transfer-Encoding', $options);
} else {
$options[CURLOPT_UPLOAD] = true;
// Let cURL handle setting the Content-Length header
if ($size !== null) {
$options[CURLOPT_INFILESIZE] = $size;
$this->removeHeader('Content-Length', $options);
}
}
// If the Expect header is not present, prevent curl from adding it
if (!$request->hasHeader('Expect')) {
$options[CURLOPT_HTTPHEADER][] = 'Expect:';
}
}
示例4: assertAuthorization
/**
* Asserts that the authorization header is correct.
*
* @param RequestInterface $request Request to test
*
* @return void
*/
protected function assertAuthorization(RequestInterface $request)
{
list($alg, $digest) = explode(' ', $request->getHeader('Authorization'));
$this->assertEquals('Basic', $alg);
$expected = self::MERCHANT_ID . ':' . self::SHARED_SECRET;
$this->assertEquals($expected, base64_decode($digest));
}
示例5: isRequestAuthorized
/**
* @param RequestInterface $httpRequest The HTTP request before it is sent.
* @return bool false if the request needs to be authorized
*/
private function isRequestAuthorized(RequestInterface $httpRequest)
{
$authorization = trim($httpRequest->getHeader('Authorization'));
if (!$authorization) {
return false;
} else {
return strpos($authorization, 'Basic') === 0;
}
}
示例6: formatBody
/**
* @param RequestInterface|ResponseInterface $message
* @return string
*/
protected function formatBody($message)
{
$header = $message->getHeader('Content-Type');
if (JsonStringFormatter::isJsonHeader($header)) {
$formatter = new JsonStringFormatter();
return $formatter->format($message->getBody());
} elseif (XmlStringFormatter::isXmlHeader($header)) {
$formatter = new XmlStringFormatter();
return $formatter->format($message->getBody());
}
$factory = new StringFactoryFormatter();
return $factory->format($message->getBody());
}
示例7: getRequestCookieValues
private function getRequestCookieValues(HttpRequest $request)
{
if (!$request->hasHeader('Cookie')) {
return [];
}
$cookieStrings = explode(';', $request->getHeader('Cookie'));
$values = [];
foreach ($cookieStrings as $cookieString) {
$cookieString = trim($cookieString);
$currentValues = explode('=', $cookieString);
$values[$currentValues[0]] = $currentValues[1];
}
return $values;
}
示例8: add_decode_content
private function add_decode_content(RequestInterface $request, RequestMediator $mediator, &$options, $value)
{
if (!$request->hasHeader('Accept-Encoding')) {
$options[CURLOPT_ENCODING] = '';
// Don't let curl send the header over the wire
$options[CURLOPT_HTTPHEADER][] = 'Accept-Encoding:';
} else {
$options[CURLOPT_ENCODING] = $request->getHeader('Accept-Encoding');
}
}
示例9: addPostData
/**
* Apply POST fields and files to a request to attempt to give an accurate
* representation.
*
* @param RequestInterface $request Request to update
* @param array $body Body to apply
*/
protected function addPostData(RequestInterface $request, array $body)
{
static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true];
$post = new PostBody();
foreach ($body as $key => $value) {
if (isset($fields[gettype($value)])) {
$post->setField($key, $value);
} elseif ($value instanceof PostFileInterface) {
$post->addFile($value);
} else {
$post->addFile(new PostFile($key, $value));
}
}
if ($request->getHeader('Content-Type') == 'multipart/form-data') {
$post->forceMultipartUpload(true);
}
$request->setBody($post);
}
示例10: createStreamResource
private function createStreamResource(RequestInterface $request, array $options, $context, &$http_response_header)
{
$url = $request->getUrl();
// Add automatic gzip decompression
if (strpos($request->getHeader('Accept-Encoding'), 'gzip') !== false) {
$url = 'compress.zlib://' . $url;
}
return $this->createResource(function () use($url, &$http_response_header, $context) {
if (false === strpos($url, 'http')) {
trigger_error("URL is invalid: {$url}", E_USER_WARNING);
return null;
}
return fopen($url, 'r', null, $context);
}, $request, $options);
}
示例11: isJson
private static function isJson(RequestInterface $request)
{
return preg_match('#^application/json#', $request->getHeader('Content-Type'));
}
示例12: getCacheKey
/**
* Hash a request URL into a string that returns cache metadata.
*
* @param RequestInterface $request The Request to generate the cache key
* for.
* @param array $vary (optional) An array of headers to vary
* the cache key by.
*
* @return string
*/
private function getCacheKey(RequestInterface $request, array $vary = [])
{
$key = $request->getMethod() . ' ' . $request->getUrl();
// If Vary headers have been passed in, fetch each header and add it to
// the cache key.
foreach ($vary as $header) {
$key .= " {$header}: " . $request->getHeader($header);
}
return $this->keyPrefix . md5($key);
}
示例13: 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 (string) $request->getHeader('x-amz-content-sha256');
}
if ($body = $request->getBody()) {
if (!$body->isSeekable()) {
throw new CouldNotCreateChecksumException('sha256');
}
return Utils::hash($body, 'sha256');
}
return self::EMPTY_PAYLOAD;
}