本文整理汇总了PHP中GuzzleHttp\Message\RequestInterface::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestInterface::getConfig方法的具体用法?PHP RequestInterface::getConfig怎么用?PHP RequestInterface::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Message\RequestInterface
的用法示例。
在下文中一共展示了RequestInterface::getConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: modifyRedirectRequest
private function modifyRedirectRequest(RequestInterface $request, ResponseInterface $response)
{
$config = $request->getConfig();
// Use a GET request if this is an entity enclosing request and we are
// not forcing RFC compliance, but rather emulating what all browsers
// would do.
$statusCode = $response->getStatusCode();
if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
$request->setMethod('GET');
$request->setBody(null);
}
$previousUrl = $request->getUrl();
$this->setRedirectUrl($request, $response);
$this->rewindEntityBody($request);
// Add the Referer header if it is told to do so and only
// add the header if we are not redirecting from https to http.
if ($config->getPath('redirect/referer') && ($request->getScheme() == 'https' || $request->getScheme() == $config['redirect_scheme'])) {
$url = Url::fromString($previousUrl);
$url->setUsername(null);
$url->setPassword(null);
$request->setHeader('Referer', (string) $url);
} else {
$request->removeHeader('Referer');
}
}
示例2: 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];
}
示例3: save
public function save(RequestInterface $request, ResponseInterface $response)
{
$ttl = (int) $request->getConfig()->get('cache.ttl');
$key = $this->getCacheKey($request);
// Persist the response body if needed
if ($response->getBody() && $response->getBody()->getSize() > 0) {
$this->cache->save($key, array('code' => $response->getStatusCode(), 'headers' => $response->getHeaders(), 'body' => (string) $response->getBody()), $ttl);
$request->getConfig()->set('cache.key', $key);
}
}
示例4: signRequest
/**
* Signs the specified request with an SellerCenter API signing protocol by using the
* provided SellerCenter API credentials and adding the required headers to the request
*
* @param RequestInterface $request Request to add a signature to
* @param CredentialsInterface $credentials Signing credentials
*/
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
$parameters = $request->getQuery()->toArray();
$parameters['UserID'] = $credentials->getId();
$parameters['Version'] = '1.0';
$parameters['Action'] = $request->getConfig()->get('command')->getName();
$parameters['Timestamp'] = gmdate(DateTime::ISO8601);
// the keys MUST be in alphabetical order to correct signature calculation
ksort($parameters);
$parameters['Signature'] = rawurlencode(hash_hmac('sha256', http_build_query($parameters, '', '&', PHP_QUERY_RFC3986), $credentials->getKey(), false));
$request->setQuery($parameters);
}
示例5: shouldValidate
private function shouldValidate(RequestInterface $request, ResponseInterface $response)
{
if ($request->getMethod() != 'GET' || $request->getConfig()->get('cache.disable')) {
return false;
}
$validate = Utils::getDirective($request, 'Pragma') === 'no-cache' || Utils::getDirective($response, 'Pragma') === 'no-cache' || Utils::getDirective($request, 'must-revalidate') || Utils::getDirective($response, 'must-revalidate') || Utils::getDirective($request, 'no-cache') || Utils::getDirective($response, 'no-cache') || Utils::getDirective($response, 'max-age') === '0' || Utils::getDirective($response, 's-maxage') === '0';
// Use the strong ETag validator if available and the response contains
// no Cache-Control directive
if (!$validate && !$response->hasHeader('Cache-Control') && $response->hasHeader('ETag')) {
$validate = true;
}
return $validate;
}
示例6: signRequest
public function signRequest(RequestInterface $request, CredentialsInterface $credentials)
{
/** @var PostBodyInterface $body */
$body = $request->getBody();
$body->setField('Timestamp', gmdate('c'));
$body->setField('SignatureVersion', '2');
$body->setField('SignatureMethod', 'HmacSHA256');
$body->setField('AWSAccessKeyId', $credentials->getAccessKeyId());
if ($token = $credentials->getSecurityToken()) {
$body->setField('SecurityToken', $token);
}
// build string to sign
$sign = $request->getMethod() . "\n" . $request->getHost() . "\n" . '/' . "\n" . $this->getCanonicalizedParameterString($body);
$request->getConfig()->set('aws.signature', $sign);
$body->setField('Signature', base64_encode(hash_hmac('sha256', $sign, $credentials->getSecretKey(), true)));
}
示例7: createRedirectRequest
/**
* Create a redirect request for a specific request object
*
* Takes into account strict RFC compliant redirection (e.g. redirect POST
* with POST) vs doing what most clients do (e.g. redirect POST with GET).
*
* @param RequestInterface $request
* @param ResponseInterface $response
*
* @return RequestInterface Returns a new redirect request
* @throws CouldNotRewindStreamException If the body cannot be rewound.
*/
private function createRedirectRequest(RequestInterface $request, ResponseInterface $response)
{
$config = $request->getConfig();
// Use a GET request if this is an entity enclosing request and we are
// not forcing RFC compliance, but rather emulating what all browsers
// would do. Be sure to disable redirects on the clone.
$redirectRequest = clone $request;
$redirectRequest->getEmitter()->detach($this);
$statusCode = $response->getStatusCode();
if ($statusCode == 303 || $statusCode <= 302 && $request->getBody() && !$config->getPath('redirect/strict')) {
$redirectRequest->setMethod('GET');
$redirectRequest->setBody(null);
}
$this->setRedirectUrl($redirectRequest, $response);
$this->rewindEntityBody($redirectRequest);
// Add the Referer header if it is told to do so and only
// add the header if we are not redirecting from https to http.
if ($config->getPath('redirect/referer') && ($redirectRequest->getScheme() == 'https' || $redirectRequest->getScheme() == $request->getScheme())) {
$url = Url::fromString($request->getUrl());
$url->setUsername(null)->setPassword(null);
$redirectRequest->setHeader('Referer', (string) $url);
}
return $redirectRequest;
}
示例8: add_decode_content
private function add_decode_content(RequestInterface $request, $value)
{
if ($value === false) {
return;
}
if ($value !== true) {
$request->setHeader('Accept-Encoding', $value);
}
$request->getConfig()['decode_content'] = true;
}
示例9: verify
/**
* Looks for a Certificate Authority file in the CA folder
* that matches the host and update the 'verify' option
* to its full path.
* If no specific file regarding a host is found, uses
* curl-ca-bundle.crt by default.
* @param RequestInterface $httpRequest
*/
private function verify(RequestInterface $httpRequest)
{
$extensions = array('crt', 'pem', 'cer', 'der');
$caDir = __DIR__ . '/../CA/';
// Must be https
$url = $httpRequest->getUrl();
if (substr($url, 0, 5) != 'https') {
$httpRequest->getConfig()->set('verify', false);
return;
}
// Default
$httpRequest->getConfig()->set('verify', $caDir . 'curl-ca-bundle.crt');
// Look for a host specific CA file
$host = strtolower(parse_url($url, PHP_URL_HOST));
if (!$host) {
return;
}
$filename = $host;
do {
// Look for the possible extensions
foreach ($extensions as $ext) {
if (file_exists($verify = $caDir . $filename . '.' . $ext)) {
$httpRequest->getConfig()->set('verify', $verify);
return;
}
}
// Remove a subdomain each time
$filename = substr($filename, strpos($filename, '.') + 1);
} while (substr_count($filename, '.') > 0);
// No specific match
return;
}
示例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: sign
public function sign(RequestInterface $request, $client_id, $client_secret)
{
$request->getConfig()->set('auth', 'basic');
$request->setHeader('Authorization', 'Basic ' . base64_encode("{$client_id}:{$client_secret}"));
}
示例12: addResponseHeaders
private function addResponseHeaders(RequestInterface $request, ResponseInterface $response)
{
$params = $request->getConfig();
$lookup = $params['cache_lookup'] . ' from GuzzleCache';
$response->addHeader('X-Cache-Lookup', $lookup);
if ($params['cache_hit'] === true) {
$response->addHeader('X-Cache', 'HIT from GuzzleCache');
} elseif ($params['cache_hit'] == 'error') {
$response->addHeader('X-Cache', 'HIT_ERROR from GuzzleCache');
} else {
$response->addHeader('X-Cache', 'MISS from GuzzleCache');
}
$freshness = Utils::getFreshness($response);
// Only add a Warning header if we are returning a stale response.
if ($params['cache_hit'] && $freshness !== null && $freshness <= 0) {
$response->addHeader('Warning', sprintf('%d GuzzleCache/' . ClientInterface::VERSION . ' "%s"', 110, 'Response is stale'));
}
}
示例13: add_wait
protected function add_wait(RequestInterface $request, $wait)
{
$request->getConfig()->set('wait', $wait);
}
示例14: 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');
}
}
示例15: applyTransferOptions
private function applyTransferOptions(RequestInterface $request, RequestMediator $mediator, array &$options)
{
static $methods;
if (!$methods) {
$methods = array_flip(get_class_methods(__CLASS__));
}
foreach ($request->getConfig()->toArray() as $key => $value) {
$method = "add_{$key}";
if (isset($methods[$method])) {
$this->{$method}($request, $mediator, $options, $value);
}
}
}