本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getHeaders方法的具体用法?PHP RequestInterface::getHeaders怎么用?PHP RequestInterface::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getHeaders方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getDefaultOptions
protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
{
$url = $request->getUrl();
// Strip fragment from URL. See:
// https://github.com/guzzle/guzzle/issues/453
if (($pos = strpos($url, '#')) !== false) {
$url = substr($url, 0, $pos);
}
$config = $request->getConfig();
$options = array(CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => array($mediator, 'writeResponseBody'), CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'), CURLOPT_READFUNCTION => array($mediator, 'readRequestBody'), CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, '_headers' => $request->getHeaders());
if (defined('CURLOPT_PROTOCOLS')) {
// Allow only HTTP and HTTPS protocols
$options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// Add CURLOPT_ENCODING if Accept-Encoding header is provided
if ($request->hasHeader('Accept-Encoding')) {
$options[CURLOPT_ENCODING] = $request->getHeader('Accept-Encoding');
// Let cURL set the Accept-Encoding header. Without this change
// curl could add a duplicate value.
$this->removeHeader('Accept-Encoding', $options);
}
// cURL sometimes adds a content-type by default. Prevent this.
if (!$request->hasHeader('Content-Type')) {
$options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
}
return $options;
}
示例2: formatHeaders
/**
* @param RequestInterface|ResponseInterface $message
* @return string
*/
protected function formatHeaders($message)
{
$headers = [];
foreach ($message->getHeaders() as $header => $value) {
$headers[] = sprintf('%s: %s', $header, implode("\n : ", $value));
}
return implode("\n", $headers);
}
示例3: createRingRequest
/**
* Creates a Ring request from a request object.
*
* This function does not hook up the "then" and "progress" events that
* would be required for actually sending a Guzzle request through a
* RingPHP handler.
*
* @param RequestInterface $request Request to convert.
*
* @return array Converted Guzzle Ring request.
*/
public static function createRingRequest(RequestInterface $request)
{
$options = $request->getConfig()->toArray();
$url = $request->getUrl();
// No need to calculate the query string twice (in URL and query).
$qs = ($pos = strpos($url, '?')) ? substr($url, $pos + 1) : null;
return ['scheme' => $request->getScheme(), 'http_method' => $request->getMethod(), 'url' => $url, 'uri' => $request->getPath(), 'headers' => $request->getHeaders(), 'body' => $request->getBody(), 'version' => $request->getProtocolVersion(), 'client' => $options, 'query_string' => $qs, 'future' => isset($options['future']) ? $options['future'] : false];
}
示例4: getDefaultOptions
protected function getDefaultOptions(RequestInterface $request, RequestMediator $mediator)
{
$url = $request->getUrl();
// Strip fragment from URL. See:
// https://github.com/guzzle/guzzle/issues/453
if (($pos = strpos($url, '#')) !== false) {
$url = substr($url, 0, $pos);
}
$config = $request->getConfig();
$options = [CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ?: 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => [$mediator, 'writeResponseBody'], CURLOPT_HEADERFUNCTION => [$mediator, 'receiveResponseHeader'], CURLOPT_READFUNCTION => [$mediator, 'readRequestBody'], CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, '_headers' => $request->getHeaders()];
if (defined('CURLOPT_PROTOCOLS')) {
// Allow only HTTP and HTTPS protocols
$options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
}
// cURL sometimes adds a content-type by default. Prevent this.
if (!$request->hasHeader('Content-Type')) {
$options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
}
return $options;
}
示例5: getRequestHeaderAsString
private function getRequestHeaderAsString(RequestInterface $request)
{
$message = vsprintf('%s %s HTTP/%s', [strtoupper($request->getMethod()), $request->getUrl(), $request->getProtocolVersion()]) . "\r\n";
foreach ($request->getHeaders() as $name => $values) {
$message .= $name . ': ' . implode(', ', $values) . "\r\n";
}
$message .= "\r\n";
return $message;
}
示例6: extractHeadersArgument
/**
* @param RequestInterface $request
*/
protected function extractHeadersArgument(RequestInterface $request)
{
$url = Url::fromString($request->getUrl());
foreach ($request->getHeaders() as $name => $header) {
if ('host' === strtolower($name) && $header[0] === $url->getHost()) {
continue;
}
if ('user-agent' === strtolower($name)) {
$this->addOption('A', escapeshellarg($header[0]));
continue;
}
foreach ((array) $header as $headerValue) {
$this->addOption('H', escapeshellarg("{$name}: {$headerValue}"));
}
}
}
示例7: getDefaultOptions
private function getDefaultOptions(RequestInterface $request)
{
$headers = '';
foreach ($request->getHeaders() as $name => $values) {
$headers .= $name . ': ' . implode(', ', $values) . "\r\n";
}
return ['http' => ['method' => $request->getMethod(), 'header' => trim($headers), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => true, 'follow_location' => 0, 'content' => (string) $request->getBody()]];
}
示例8: error
/**
* Handle an error. We handle errors by throwing an exception.
*
* @param string $error An error code representing the error
* (use_underscore_separators).
* @param string|null $message The error message.
* @param \GuzzleHttp\Message\RequestInterface|null $request Optional. The
* Guzzle request object.
* @param \GuzzleHttp\Message\ResponseInterface|null $response Optional. The
* Guzzle response object.
*
* @return void
* @throws \Box\View\BoxViewException
*/
protected static function error($error, $message = null, $request = null, $response = null)
{
if (!empty($request)) {
$message .= "\n";
$message .= 'Method: ' . $request->getMethod() . "\n";
$message .= 'URL: ' . $request->getUrl() . "\n";
$message .= 'Query: ' . json_encode($request->getQuery()->toArray()) . "\n";
$message .= 'Headers: ' . json_encode($request->getHeaders()) . "\n";
$message .= 'Request Body: ' . $request->getBody() . "\n";
}
if (!empty($response)) {
$message .= "\n";
$message .= 'Response Body: ' . $response->getBody() . "\n";
}
$exception = new BoxViewException($message);
$exception->errorCode = $error;
throw $exception;
}
示例9: getZboziApiRequest
/**
* @param \GuzzleHttp\Message\RequestInterface $request
* @return \SlevomatZboziApi\Request\ZboziApiRequest
*/
private function getZboziApiRequest(\GuzzleHttp\Message\RequestInterface $request)
{
return new ZboziApiRequest($request->getMethod(), $request->getUrl(), $request->getHeaders(), $request->getBody() === null ? null : json_decode((string) $request->getBody()));
}
示例10: createCanonicalizedAmzHeaders
private function createCanonicalizedAmzHeaders(RequestInterface $request)
{
$headers = [];
foreach ($request->getHeaders() as $name => $header) {
$name = strtolower($name);
if (strpos($name, 'x-amz-') === 0) {
$value = implode(',', $header);
if (strlen($value) > 0) {
$headers[$name] = $name . ':' . $value;
}
}
}
if (!$headers) {
return '';
}
ksort($headers);
return implode("\n", $headers) . "\n";
}
示例11: moveHeadersToQuery
private function moveHeadersToQuery(RequestInterface $request)
{
$query = $request->getQuery();
foreach ($request->getHeaders() as $name => $header) {
$name = strtolower($name);
if (substr($name, 0, 5) == 'x-amz') {
$query[$name] = $header;
}
if ($name !== 'host') {
$request->removeHeader($name);
}
}
}
示例12: collectRequest
/**
* Collect & sanitize data about a Guzzle request.
*
* @param RequestInterface $request Guzzle request.
* @return array
*/
private function collectRequest(RequestInterface $request)
{
$query = $request->getQuery();
return ['headers' => $request->getHeaders(), 'method' => $request->getMethod(), 'scheme' => $request->getScheme(), 'host' => $request->getHost(), 'path' => $request->getPath(), 'query' => (string) $query, 'queryParams' => $query->toArray(), 'body' => (string) $request->getBody()];
}