php Guzzle-Http-Message-Request类(方法)实例源码

下面列出了php Guzzle-Http-Message-Request 类(方法)源码代码实例,从而了解它的用法。

作者:KANU8    项目:guzzl   
public function testHandles404RevalidationResponses()
 {
     $request = new Request('GET', 'http://foo.com');
     $request->setClient(new Client());
     $badResponse = new Response(404, array(), 'Oh no!');
     $badRequest = clone $request;
     $badRequest->setResponse($badResponse, true);
     $response = new Response(200, array(), 'foo');
     $plugin = new CachePlugin();
     $c = new ArrayCache();
     $c->save('foo', array(200, array(), 'foo'));
     $s = new DefaultCacheStorage(new DoctrineCacheAdapter($c));
     $k = new CallbackCacheKeyProvider(function () {
         return 'foo';
     });
     $rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($k, $s, $plugin))->setMethods(array('createRevalidationRequest'))->getMock();
     $rev->expects($this->once())->method('createRevalidationRequest')->will($this->returnValue($badRequest));
     try {
         $rev->revalidate($request, $response);
         $this->fail('Should have thrown an exception');
     } catch (BadResponseException $e) {
         $this->assertSame($badResponse, $e->getResponse());
         $this->assertFalse($c->fetch('foo'));
     }
 }

作者:cosmoroger    项目:http-moc   
public function setUp()
 {
     $this->client = $this->getSimpleMock('Guzzle\\Http\\ClientInterface');
     $this->facade = new RequestCollectionFacade($this->client);
     $this->request = new Request('GET', '/_request/last');
     $this->request->setClient($this->client);
 }

作者:yuri-sagalovic    项目:nextcaller-php-ap   
/**
  * @param Request $request
  * @return array|null
  * @throws BadResponseException
  * @throws FormatException
  */
 protected function proceedResponse(Request $request)
 {
     try {
         $response = $request->send();
     } catch (ClientErrorResponseException $e) {
         $response = $e->getResponse();
     }
     $body = $response->getBody(true);
     if (empty($body) && $response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
         return null;
     }
     $result = json_decode($body, true);
     if ($result === null) {
         # When response is just a sting.
         $result = $body;
     }
     if ($response->getStatusCode() >= 200 && $response->getStatusCode() < 300) {
         return $result;
     }
     if (!$result || !$result['error']) {
         throw new FormatException('Not valid error response', 3, null, $request, $response);
     }
     $message = $result['error']['message'];
     $code = $result['error']['code'];
     if ($response->getStatusCode() == 429) {
         throw new RateLimitException($message, $code, null, $request, $response);
     }
     $e = new BadResponseException($message, $code, null, $request, $response);
     $e->setError($result['error']);
     throw $e;
 }

作者:brainver    项目:Paw   
protected function generateRequest($url, array $subProtocols, array $headers)
 {
     $headers = array_merge($this->defaultHeaders, $headers);
     $headers['Sec-WebSocket-Key'] = $this->generateKey();
     $request = new Request('GET', $url, $headers);
     $scheme = strtolower($request->getScheme());
     if (!in_array($scheme, ['ws', 'wss'])) {
         throw new \InvalidArgumentException(sprintf('Cannot connect to invalid URL (%s)', $url));
     }
     $request->setScheme('HTTP');
     if (!$request->getPort()) {
         $request->setPort('wss' === $scheme ? 443 : 80);
     } else {
         $request->setHeader('Host', $request->getHeader('Host') . ":{$request->getPort()}");
     }
     if (!$request->getHeader('Origin')) {
         $request->setHeader('Origin', str_replace('ws', 'http', $scheme) . '://' . $request->getHost());
     }
     // do protocol headers
     if (count($subProtocols) > 0) {
         $protocols = implode(',', $subProtocols);
         if ($protocols != "") {
             $request->setHeader('Sec-WebSocket-Protocol', $protocols);
         }
     }
     return $request;
 }

作者:opdavie    项目:nwdrupalwebsit   
public function testOnRequestBeforeSendPOST()
 {
     $request = new Request('POST', 'www.url.com');
     $event = new Event(array('request' => $request));
     $this->plugin->onRequestBeforeSend($event);
     $this->assertContains('key=' . $this->key, $request->getUrl());
 }

作者:puterakahf    项目:FriendlyContext   
function it_set_up_request_custom_authentication_when_provided(Request $request, RequestBuilder $builder)
 {
     $this->beConstructedWith('digest');
     $request->setAuth('username', 'password', 'digest')->shouldBeCalled(1);
     $builder->getCredentials()->shouldBeCalled()->willReturn(['username' => 'username', 'password' => 'password']);
     $this->secureRequest($request, $builder);
 }

作者:arthurwayn    项目:ovh-sdk-ph   
public function debug()
 {
     $r = new Response();
     var_dump($r->getReasonPhrase());
     $req = new Request();
     $req->getPath();
 }

作者:cpliaka    项目:bigoven-ph   
/**
  * @param \Guzzle\Http\Message\Request $request
  * @param string $username
  * @param string $password
  *
  * @return \BigOven\BigOvenAuthPlugin
  */
 public function addAuthorizationHeader(Request $request, $username, $password)
 {
     $encodedString = base64_encode($username . ':' . $password);
     $headerValue = 'Basic ' . $encodedString;
     $request->addHeader('Authorization', $headerValue);
     return $this;
 }

作者:puterakahf    项目:FriendlyContext   
public function secureRequest(Request $request, RequestBuilder $builder)
 {
     $credentials = $builder->getCredentials();
     if (!isset($credentials['username']) || !isset($credentials['password'])) {
         throw new \RuntimeException('You must specified a "username" and a "password" for the http basic authentication.');
     }
     $request->setAuth($credentials['username'], $credentials['password']);
 }

作者:sheknow    项目:ooyala-api-clien   
/**
  * Guzzle should take care of encoding signatures. This test is just a safety net to ensure that happens.
  */
 public function testUrlEncodedSignature()
 {
     $expected = '1234 ] 5678';
     $request = new Request('GET', "/fake?signature={$expected}");
     $url = explode('signature=', $request->getUrl());
     $signature = end($url);
     $this->assertEquals(rawurlencode($expected), $signature, 'Request should be encoding the signature before sending (required by Ooyala).');
 }

作者:faouzi    项目:composer-conversation-proxy-provide   
private function fireRequest(GuzzleRequest $request, $cookie)
 {
     try {
         $response = $request->addCookie('authenticator', $cookie)->send();
         return $response->json();
     } catch (\Guzzle\Http\Exception\BadResponseException $client_error) {
         return $this->app->abort($client_error->getResponse()->getStatusCode(), $client_error->getResponse()->getReasonPhrase());
     }
 }

作者:mpscholte    项目:github-ap   
public function testOnRequestBeforeSend()
 {
     $request = new Request('GET', 'https://example.com');
     $event = new Event(['request' => $request]);
     $oauth = new OAuth('example');
     $oauth->onRequestBeforeSend($event);
     $this->assertTrue($request->getQuery()->hasKey('access_token'));
     $this->assertEquals('example', $request->getQuery()->get('access_token'));
 }

作者:myrichhu    项目:mssapi_ph   
public function testCreatesPreSignedUrlWithXAmzHeaders()
 {
     $signature = new S3Signature();
     $request = new Request('GET', 'https://s3.amazonaws.com', array('X-Amz-Acl' => 'public-read'));
     $c = $this->getServiceBuilder()->get('s3');
     $request->setClient($c);
     $this->assertContains('x-amz-acl:public-read', $signature->createCanonicalizedString($request, time()));
     $this->assertContains('&x-amz-acl=public-read', $signature->createPresignedUrl($request, $c->getCredentials(), time()));
 }

作者:spiaseck    项目:ubirim   
public function request(Request $request)
 {
     try {
         $response = $request->send();
     } catch (\Exception $e) {
         throw new ApiException($e->getMessage(), $e->getCode(), $e);
     }
     $apiResponse = new ApiResponse($response->getBody(), $response->getStatusCode(), $response->getContentType());
     return $apiResponse;
 }

作者:cstude    项目:nagios-plugin   
/**
  * @covers Aws\Common\Signature\AbstractSignature::getCanonicalizedQueryString
  * @dataProvider queryStringProvider
  */
 public function testCreatesCanonicalizedQueryString($headers, $string)
 {
     // Make the method publicly callable
     $method = new \ReflectionMethod('Aws\\Common\\Signature\\AbstractSignature', 'getCanonicalizedQueryString');
     $method->setAccessible(true);
     // Create a request and replace the headers with the test headers
     $request = new Request('GET', 'http://www.example.com');
     $request->getQuery()->replace($headers);
     $this->assertEquals($string, $method->invoke($this->signature, $request));
 }

作者:GedCon    项目:zfr-pushe   
/**
  * @covers PusherSignature::signRequest
  */
 public function testAssertEmptyParametersAreStrippedWhenSignRequest()
 {
     $request = new HttpRequest('POST', '/apps/3/events');
     // We set variables in query to have always the same result
     $request->getQuery()->replace(array('key-with-value' => 'value', 'key-without-value' => ''));
     $this->pusherSignature->signRequest($request, $this->credentials);
     $queryParameters = $request->getQuery()->toArray();
     $this->assertArrayHasKey('key-with-value', $queryParameters);
     $this->assertArrayNotHasKey('key-without-value', $queryParameters);
 }

作者:TheJaniceTon    项目:PhpSd   
public function setRequestAuthentication(\Guzzle\Http\Message\Request $request)
 {
     $oauthAccessToken = $this->configuration->get('oauthAccessToken');
     // Do we have an oAuth2 access token?
     if (!empty($oauthAccessToken)) {
         $request->setHeader('Authorization', 'Bearer ' . $oauthAccessToken);
     } else {
         // Otherwise, use basic authentication
         $request->setAuth($this->configuration->get('apiToken'), $this->configuration->get('apiSecret'));
     }
     return $request;
 }

作者:Frinsti    项目:AlfredWorkflow.co   
public function testFiltersCacheKey()
 {
     $request = new Request('GET', 'http://foo.com?a=b&c=d', array('Abc' => '123', 'Def' => '456'));
     $request->getParams()->set(DefaultCacheKeyProvider::CACHE_KEY_FILTER, 'header=Def; query=c');
     $provider = new DefaultCacheKeyProvider();
     $provider->getCacheKey($request);
     $this->assertNotEmpty($request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY));
     $cloned = clone $request;
     $cloned->getQuery()->remove('c');
     $cloned->removeHeader('Def');
     $this->assertEquals((string) $cloned, $request->getParams()->get(DefaultCacheKeyProvider::CACHE_KEY_RAW));
 }

作者:aptom    项目:silex-extra   
public function testListenerShouldAppendToRemoteHeadersAddTokenHeader()
 {
     $token = 'foo';
     $requestStack = new RequestStack();
     $plugin = new RequestTokenPlugin($token, $requestStack);
     $httpRequest = new \Symfony\Component\HttpFoundation\Request();
     $httpRequest->headers->set('x-remote-request-token', 'bar');
     $requestStack->push($httpRequest);
     $guzzleRequest = new Request('GET', 'http://example.com');
     $event = new Event(array('request' => $guzzleRequest));
     $plugin->onBeforeRequestSend($event);
     $this->assertEquals('bar foo', $guzzleRequest->getHeaders()->get('x-remote-request-token'));
 }

作者:cstude    项目:nagios-plugin   
/**
  * @covers Aws\Common\Signature\SignatureListener
  */
 public function testSignsRequestsProperly()
 {
     $request = new Request('GET', 'http://www.example.com');
     $request->getEventDispatcher();
     $credentials = new Credentials('a', 'b');
     $signature = $this->getMock('Aws\\Common\\Signature\\SignatureV4');
     // Ensure that signing the request occurred once with the correct args
     $signature->expects($this->once())->method('signRequest')->with($this->equalTo($request), $this->equalTo($credentials));
     $listener = new SignatureListener($credentials, $signature);
     // Create a mock event
     $event = new Event(array('request' => $request));
     $listener->onRequestBeforeSend($event);
 }


问题


面经


文章

微信
公众号

扫码关注公众号