本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::hasHeader方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::hasHeader方法的具体用法?PHP RequestInterface::hasHeader怎么用?PHP RequestInterface::hasHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::hasHeader方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addExpectHeader
private function addExpectHeader(RequestInterface $request, StreamInterface $body)
{
// Determine if the Expect header should be used
if ($request->hasHeader('Expect')) {
return;
}
$expect = $request->getConfig()['expect'];
// Return if disabled or if you're not using HTTP/1.1
if ($expect === false || $request->getProtocolVersion() !== '1.1') {
return;
}
// The expect header is unconditionally enabled
if ($expect === true) {
$request->setHeader('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
$size = $body->getSize();
if ($size === null || $size >= (int) $expect || !$body->isSeekable()) {
$request->setHeader('Expect', '100-Continue');
}
}
示例2: after
public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
{
foreach ($this->buffered as $param) {
$this->visitWithValue($command[$param->getName()], $param, $command);
}
$this->buffered = array();
$additional = $operation->getAdditionalParameters();
if ($additional && $additional->getLocation() == $this->locationName) {
foreach ($command->toArray() as $key => $value) {
if (!$operation->hasParam($key)) {
$additional->setName($key);
$this->visitWithValue($value, $additional, $command);
}
}
$additional->setName(null);
}
// If data was found that needs to be serialized, then do so
$xml = null;
if ($this->writer) {
$xml = $this->finishDocument($this->writer);
} elseif ($operation->getData('xmlAllowEmpty')) {
// Check if XML should always be sent for the command
$writer = $this->createRootElement($operation);
$xml = $this->finishDocument($writer);
}
if ($xml) {
$request->setBody(Stream::factory($xml));
// Don't overwrite the Content-Type if one is set
if ($this->contentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->contentType);
}
}
$this->writer = null;
}
示例3: 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);
}
示例4: applyRequestHeaders
/**
* Applies request headers to a request based on the POST state
*
* @param RequestInterface $request Request to update
*/
public function applyRequestHeaders(RequestInterface $request)
{
if ($this->files || $this->forceMultipart) {
$request->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->getBody()->getBoundary());
} elseif ($this->fields && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', 'application/x-www-form-urlencoded');
}
if ($size = $this->getSize()) {
$request->setHeader('Content-Length', $size);
}
}
示例5: 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;
}
示例6: after
public function after(GuzzleCommandInterface $command, RequestInterface $request, Operation $operation, array $context)
{
$data = $this->jsonData;
$this->jsonData = null;
// Add additional parameters to the JSON document
$additional = $operation->getAdditionalParameters();
if ($additional && $additional->getLocation() == $this->locationName) {
foreach ($command->toArray() as $key => $value) {
if (!$operation->hasParam($key)) {
$data[$key] = $this->prepareValue($value, $additional);
}
}
}
// Don't overwrite the Content-Type if one is set
if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->jsonContentType);
}
$request->setBody(Stream::factory(json_encode($data)));
}
示例7: 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');
}
}
示例8: add_json
private function add_json(RequestInterface $request, $value)
{
if (!$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', 'application/json');
}
$request->setBody(Stream::factory(json_encode($value)));
}
示例9: applyHeaders
private function applyHeaders(RequestInterface $request, array &$options)
{
foreach ($options['_headers'] as $name => $values) {
$options[CURLOPT_HTTPHEADER][] = $name . ': ' . implode(', ', $values);
}
// Remove the Expect header if one was not set
if (!$request->hasHeader('Accept')) {
$options[CURLOPT_HTTPHEADER][] = 'Accept:';
}
}
示例10: applyOptions
protected function applyOptions(RequestInterface $request, array $options = [])
{
$config = $request->getConfig();
$emitter = $request->getEmitter();
foreach ($options as $key => $value) {
if (isset(self::$configMap[$key])) {
$config[$key] = $value;
continue;
}
switch ($key) {
case 'allow_redirects':
if ($value === false) {
continue;
}
if ($value === true) {
$value = self::$defaultRedirect;
} elseif (!isset($value['max'])) {
throw new Iae('allow_redirects must be true, false, or an ' . 'array that contains the \'max\' key');
} else {
// Merge the default settings with the provided settings
$value += self::$defaultRedirect;
}
$config['redirect'] = $value;
$emitter->attach($this->redirectPlugin);
break;
case 'decode_content':
if ($value === false) {
continue;
}
$config['decode_content'] = true;
if ($value !== true) {
$request->setHeader('Accept-Encoding', $value);
}
break;
case 'headers':
if (!is_array($value)) {
throw new Iae('header value must be an array');
}
// Do not overwrite existing headers
foreach ($value as $k => $v) {
if (!$request->hasHeader($k)) {
$request->setHeader($k, $v);
}
}
break;
case 'exceptions':
if ($value === true) {
$emitter->attach($this->errorPlugin);
}
break;
case 'body':
if (is_array($value)) {
$this->addPostData($request, $value);
} elseif ($value !== null) {
$request->setBody(Stream::factory($value));
}
break;
case 'auth':
if (!$value) {
continue;
}
if (is_array($value)) {
$type = isset($value[2]) ? strtolower($value[2]) : 'basic';
} else {
$type = strtolower($value);
}
$config['auth'] = $value;
if ($type == 'basic') {
$request->setHeader('Authorization', 'Basic ' . base64_encode("{$value['0']}:{$value['1']}"));
} elseif ($type == 'digest') {
// @todo: Do not rely on curl
$config->setPath('curl/' . CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
$config->setPath('curl/' . CURLOPT_USERPWD, "{$value['0']}:{$value['1']}");
}
break;
case 'query':
if ($value instanceof Query) {
$original = $request->getQuery();
// Do not overwrite existing query string variables by
// overwriting the object with the query string data passed
// in the URL
$value->overwriteWith($original->toArray());
$request->setQuery($value);
} elseif (is_array($value)) {
// Do not overwrite existing query string variables
$query = $request->getQuery();
foreach ($value as $k => $v) {
if (!isset($query[$k])) {
$query[$k] = $v;
}
}
} else {
throw new Iae('query must be an array or Query object');
}
break;
case 'cookies':
if ($value === true) {
static $cookie = null;
if (!$cookie) {
$cookie = new Cookie();
//.........这里部分代码省略.........
示例11: after
public function after(CommandInterface $command, RequestInterface $request, Operation $operation, array $context)
{
if ($this->jsonContentType && !$request->hasHeader('Content-Type')) {
$request->setHeader('Content-Type', $this->jsonContentType);
}
}
示例12: canCacheRequest
/**
* Default function used to determine if a request can be cached.
*
* @param RequestInterface $request Request to check
*
* @return bool
*/
public static function canCacheRequest(RequestInterface $request)
{
$method = $request->getMethod();
// Only GET and HEAD requests can be cached
if ($method !== 'GET' && $method !== 'HEAD') {
return false;
}
// Don't fool with Range requests for now
if ($request->hasHeader('Range')) {
return false;
}
return self::getDirective($request, 'no-store') === null;
}
示例13: add_headers
private function add_headers(RequestInterface $request, $value)
{
if (!is_array($value)) {
throw new \InvalidArgumentException('header value must be an array');
}
// Do not overwrite existing headers
foreach ($value as $k => $v) {
if (!$request->hasHeader($k)) {
$request->setHeader($k, $v);
}
}
}
示例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 (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;
}