当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::setRequest方法代码示例

本文整理汇总了PHP中Guzzle\Http\Message\Response::setRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::setRequest方法的具体用法?PHP Response::setRequest怎么用?PHP Response::setRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Guzzle\Http\Message\Response的用法示例。


在下文中一共展示了Response::setRequest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddsUserAgentIfAvailable

 public function testAddsUserAgentIfAvailable()
 {
     $response = new Response(200);
     $response->setRequest(new Request('GET', 'http://www.foo.com', array('User-Agent' => 'Foo/Bar')));
     $e = new ServiceResponseException('Foo!');
     $e->setExceptionCode('foo');
     $e->setExceptionType('client');
     $e->setRequestId('xyz');
     $e->setResponse($response);
     $this->assertEquals('Aws\\Common\\Exception\\ServiceResponseException: AWS Error Code: foo, Status Code: 200, AWS Request ID: xyz, AWS Error Type: client, AWS Error Message: Foo!, User-Agent: Foo/Bar', (string) $e);
 }
开发者ID:cstuder,项目名称:nagios-plugins,代码行数:11,代码来源:ServiceResponseExceptionTest.php

示例2: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response, $queued = false)
 {
     // Never overwrite the request associated with the response (useful for redirect history)
     if (!$response->getRequest()) {
         $response->setRequest($this);
     }
     if ($queued) {
         $this->getEventDispatcher()->addListener('request.before_send', function ($e) use($response) {
             $e['request']->setResponse($response);
         }, -9999);
     } else {
         $this->response = $response;
         // If a specific response body is specified, then use it instead of the response's body
         if ($this->responseBody && !$this->responseBody->getCustomData('default')) {
             $this->getResponseBody()->write((string) $this->response->getBody());
         } else {
             $this->responseBody = $this->response->getBody();
         }
         $this->processResponse();
     }
     return $this;
 }
开发者ID:kameshwariv,项目名称:testexample,代码行数:25,代码来源:Request.php

示例3: testSetRequest

 /**
  * @covers Guzzle\Http\Message\Response::setRequest
  */
 public function testSetRequest()
 {
     $response = new Response(200);
     $this->assertNull($response->getRequest());
     $r = new \Guzzle\Http\Message\Request('GET', 'http://www.guzzle-project.com/');
     $response->setRequest($r);
     $this->assertEquals($r, $response->getRequest());
 }
开发者ID:KANU82,项目名称:guzzle,代码行数:11,代码来源:ResponseTest.php

示例4: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response, $queued = false)
 {
     // Never overwrite the request associated with the response (useful for redirect history)
     if (!$response->getRequest()) {
         $response->setRequest($this);
     }
     if ($queued) {
         $this->getParams()->set('queued_response', $response);
     } else {
         $this->getParams()->remove('queued_response');
         $this->response = $response;
         $this->responseBody = $response->getBody();
         $this->processResponse();
     }
     $this->dispatch('request.set_response', $this->getEventArray());
     return $this;
 }
开发者ID:harmoniouscrab,项目名称:BSc_Project_Program,代码行数:20,代码来源:Request.php

示例5: onRequestError

 /**
  * If possible, return a cache response on an error
  *
  * @param Event $event
  */
 public function onRequestError(Event $event)
 {
     $request = $event['request'];
     if (!$this->canCache->canCacheRequest($request)) {
         return;
     }
     $cacheKey = $this->keyProvider->getCacheKey($request);
     if ($cachedData = $this->storage->fetch($cacheKey)) {
         $response = new Response($cachedData[0], $cachedData[1], $cachedData[2]);
         $response->setRequest($request);
         $response->setHeader('Age', time() - strtotime($response->getLastModified() ?: $response->getDate() ?: 'now'));
         if ($this->canResponseSatisfyFailedRequest($request, $response)) {
             $request->getParams()->set('cache.hit', 'error');
             $this->addResponseHeaders($cacheKey, $request, $response);
             $event['response'] = $response;
             $event->stopPropagation();
         }
     }
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:24,代码来源:CachePlugin.php

示例6: setResponse

 /**
  * {@inheritdoc}
  */
 public function setResponse(Response $response, $queued = false)
 {
     $response->setRequest($this);
     if ($queued) {
         $this->getParams()->set('queued_response', $response);
     } else {
         $this->getParams()->remove('queued_response');
         $this->response = $response;
         $this->responseBody = $response->getBody();
         $this->processResponse();
     }
     $this->dispatch('request.set_response', $this->getEventArray());
     return $this;
 }
开发者ID:jsnshrmn,项目名称:Suma,代码行数:17,代码来源:Request.php

示例7: testAddsCookiesFromResponseWithRequest

 public function testAddsCookiesFromResponseWithRequest()
 {
     $response = new Response(200, array('Set-Cookie' => "fpc=d=.Hm.yh4.1XmJWjJfs4orLQzKzPImxklQoxXSHOZATHUSEFciRueW_7704iYUtsXNEXq0M92Px2glMdWypmJ7HIQl6XIUvrZimWjQ3vIdeuRbI.FNQMAfcxu_XN1zSx7l.AcPdKL6guHc2V7hIQFhnjRW0rxm2oHY1P4bGQxFNz7f.tHm12ZD3DbdMDiDy7TBXsuP4DM-&v=2; expires=Fri, 02-Mar-2019 02:17:40 GMT;"));
     $response->setRequest(new Request('GET', 'http://www.example.com'));
     $this->jar->addCookiesFromResponse($response);
     $this->assertEquals(1, count($this->jar));
 }
开发者ID:nickpeirson,项目名称:guzzle,代码行数:7,代码来源:ArrayCookieJarTest.php

示例8: setRequestOnResponse

 /**
  * Set a request closure on a response
  *
  * @param Response $response
  * @deprecated
  */
 protected function setRequestOnResponse(Response $response)
 {
     $headers = $this->getRawHeaders();
     $response->setEffectiveUrl((string) $this->url);
     $response->setRequest(function () use($headers) {
         return RequestFactory::getInstance()->fromMessage($headers);
     });
 }
开发者ID:creazy412,项目名称:vmware-win10-c65-drupal7,代码行数:14,代码来源:Request.php

示例9: testDeterminesIfItCanBeCached

 /**
  * @covers Guzzle\Http\Message\Response::canCache
  */
 public function testDeterminesIfItCanBeCached()
 {
     $this->assertTrue($this->getResponse(200)->canCache());
     $this->assertTrue($this->getResponse(410)->canCache());
     $this->assertFalse($this->getResponse(404)->canCache());
     $this->assertTrue($this->getResponse(200, array('Cache-Control' => 'public'))->canCache());
     // This has the no-store directive
     $this->assertFalse($this->getResponse(200, array('Cache-Control' => 'private, no-store'))->canCache());
     // The body cannot be read, so it cannot be cached
     $tmp = tempnam('/tmp', 'not-readable');
     $resource = fopen($tmp, 'w');
     $this->assertFalse($this->getResponse(200, array('Transfer-Encoding' => 'chunked'), EntityBody::factory($resource, 10))->canCache());
     unlink($tmp);
     // The body is 0 length, cannot be read, so it can be cached
     $tmp = tempnam('/tmp', 'not-readable');
     $resource = fopen($tmp, 'w');
     $this->assertTrue($this->getResponse(200, array(array('Content-Length' => 0)), EntityBody::factory($resource, 0))->canCache());
     unlink($tmp);
     // When an HTTPS request is sent and the Cache-Control directive does
     // not include a 'public' value, then the response is not to be cached
     $request = RequestFactory::getInstance()->create('GET', 'https://www.test.com/');
     $response = new Response(200);
     $response->setRequest($request);
     $this->assertFalse($response->canCache());
     // This response can be cache because it is public
     $response->setHeader('Cache-Control', 'public');
     $this->assertTrue($response->canCache());
 }
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:31,代码来源:ResponseTest.php

示例10: sendRequest

    /**
     * Overrides default Guzzle usage of curl_multi_exec by a simple curl call
     * and adds some metrics in Newrelic
     *
     * @param EntityEnclosingRequest $request
     * @return Response
     */
    public static function sendRequest( EntityEnclosingRequest $request )
    {
        $ch = curl_init($request->getUrl());
        $curlOptions = array(
            CURLOPT_URL            => $request->getUrl(),
            CURLOPT_TIMEOUT        => \eZINI::instance('merck.ini')->variable('WebService', 'ESBTimeout'),
            CURLOPT_CONNECTTIMEOUT => \eZINI::instance('merck.ini')->variable('WebService', 'ESBConnectTimeout'),
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_HEADER         => true,
            CURLOPT_USERAGENT      => (string) $request->getHeader('User-Agent'),
            CURLOPT_PORT           => $request->getPort(),
            CURLOPT_HTTPHEADER     => $request->getHeaderLines(),
            CURLOPT_HTTP_VERSION   => $request->getProtocolVersion() === '1.0'
                    ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1,
            // Verifies the authenticity of the peer's certificate
            CURLOPT_SSL_VERIFYPEER => 1,
            // Certificate must indicate that the server is the server to which you meant to connect
            CURLOPT_SSL_VERIFYHOST => 2,
            CURLOPT_POST           => true,
            CURLOPT_POSTFIELDS     => (string) $request->getBody(),
            CURLOPT_VERBOSE        => false,
        );
        curl_setopt_array($ch, $curlOptions);

        $start = microtime(true);
        $curlResult = curl_exec( $ch );
        $curlCallTime = ( microtime(true) - $start ) * 1000;

        $newRelicApi = new \klpNrApi();
        $methodLabel =   preg_match('#/(?P<method>[^/?]+)(?:\?.*)?$#', $request->getUrl(), $m)
            ? ucfirst( $m['method'] )
            : 'Unknown';
        $newRelicApi->addParameter( 'ESB/'.$methodLabel.':'.$request->getPort(), $curlCallTime );
        $newRelicApi->setCustomMetric( 'Custom/ESB/'.$methodLabel, $curlCallTime );

        $body               = $curlResult;
        $maxHeaderBlocks    = 5;
        $index              = 0;

        // We have to deal with HTTP/1.1 100 continue headers
        do
        {
            list( $header, $body ) = explode("\r\n\r\n", $body, 2);
            $index++;
        }
        while( $index < $maxHeaderBlocks && strpos($body, 'HTTP/1') === 0 );

        $parsedHeaders = array();
        foreach( explode("\n", $header) as $h )
        {
            list( $key, $val ) = explode(':', $h);
            $parsedHeaders[trim($key)] = trim($val);
        }
        $http_status = curl_getinfo( $ch, CURLINFO_HTTP_CODE );

        if ( \eZINI::instance('merck.ini')->variable( 'WebService', 'CurlGetInfo' ) == 'enabled' )
        {
            $curlInfo = curl_getinfo($ch);
            $logMessage  = \ClusterTool::clusterIdentifier().'::'.$methodLabel."\n";
            $logMessage .= var_export( $curlInfo, true );

            \eZLog::write($logMessage, 'esbcurldetails.log');
        }

        curl_close($ch);

        $response = new Response( $http_status, $parsedHeaders, $body );
        $response->setRequest($request);
        $request->setResponse($response);

        return $response;
    }
开发者ID:sushilbshinde,项目名称:ezpublish-study,代码行数:79,代码来源:GuzzleCurlHelper.php


注:本文中的Guzzle\Http\Message\Response::setRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。