作者:pompdelu
项目:kraken-bundl
/**
* Get the response of the query.
* Will be the json decoded data if success, else the error message.
*
* @return array|string
*/
public function getResponse()
{
if (false === $this->response->isSuccessful()) {
return $this->response->getMessage();
}
return $this->response->json();
}
作者:steverhoade
项目:async-talk-example
public function dispatch($request, $connection)
{
$response = new Response(200);
$path = $request->getPath();
if ($this->match($path)) {
echo "Found match for path: {$path}" . PHP_EOL;
if (is_callable($this->routes[$path])) {
call_user_func_array($this->routes[$path], array($request, $response, $connection));
} else {
throw new \Exception('Invalid route definition.');
}
return;
}
if (is_null($this->fileHandler)) {
throw new \Exception('No file handler configured');
}
if (false === $this->fileHandler->canHandleRequest($request)) {
$response->setStatus(404);
$response->setBody('File not found');
$connection->send($response);
$connection->close();
return;
}
$this->fileHandler->handleRequest($request, $response, $connection);
}
作者:ebeauchamp
项目:brilliantretai
/**
* {@inheritdoc}
*/
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($response && $response->isClientError()) {
$parts = $this->exceptionParser->parse($request, $response);
return isset(self::$throttlingExceptions[$parts['code']]) ? true : null;
}
}
作者:jsnshrm
项目:Sum
public function testProperlyValidatesWhenUsingContentEncoding()
{
$plugin = new Md5ValidatorPlugin(true);
$request = RequestFactory::getInstance()->create('GET', 'http://www.test.com/');
$request->getEventDispatcher()->addSubscriber($plugin);
// Content-MD5 is the MD5 hash of the canonical content after all
// content-encoding has been applied. Because cURL will automatically
// decompress entity bodies, we need to re-compress it to calculate.
$body = EntityBody::factory('abc');
$body->compress();
$hash = $body->getContentMd5();
$body->uncompress();
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'gzip'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
$this->assertEquals('abc', $response->getBody(true));
// Try again with an unknown encoding
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'foobar'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with compress
$body->compress('bzip2.compress');
$response = new Response(200, array('Content-MD5' => $body->getContentMd5(), 'Content-Encoding' => 'compress'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with encoding and disabled content-encoding checks
$request->getEventDispatcher()->removeSubscriber($plugin);
$plugin = new Md5ValidatorPlugin(false);
$request->getEventDispatcher()->addSubscriber($plugin);
$request->dispatch('request.complete', array('response' => $response));
}
作者:adrianoaguia
项目:magento-elasticsearch-modul
/**
* Receive a response header from curl
*
* @param resource $curl Curl handle
* @param string $header Received header
*
* @return int
*/
public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array('request' => $this, 'line' => $header, 'status_code' => $code, 'reason_phrase' => $status));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(trim(substr($header, 0, $pos)), trim(substr($header, $pos + 1)));
}
return $length;
}
作者:duells
项目:pockpac
public function testRetrieving()
{
$response = new Response(200);
$response->setBody(json_encode(array('status' => 1, 'complete' => 1, 'list' => array(123 => array('item_id' => 123, 'resolved_id' => 123, 'given_url' => 'http://acairns.co.uk', 'given_title' => 'Andrew Cairns', 'favorite' => 0, 'status' => 0, 'time_added' => time(), 'time_updated' => time(), 'time_read' => 0, 'time_favorited' => 0, 'sort_id' => 0, 'resolved_title' => 'Andrew Cairns', 'resolved_url' => 'http://acairns.co.uk', 'excerpt' => 'Some excerpt about something', 'is_article' => 0, 'is_index' => 0, 'has_video' => 0, 'has_image' => 0, 'word_count' => 123)))));
$this->setPocketResponse($response);
$response = $this->pockpack->retrieve();
$this->assertEquals(1, $response->status);
$this->assertEquals(1, $response->complete);
$this->assertNotEmpty($response->list);
$this->assertNotEmpty($response->list->{123});
$item = $response->list->{123};
$this->assertEquals(123, $item->item_id);
$this->assertEquals(123, $item->resolved_id);
$this->assertEquals('Andrew Cairns', $item->given_title);
$this->assertEquals('Andrew Cairns', $item->resolved_title);
$this->assertEquals('http://acairns.co.uk', $item->given_url);
$this->assertEquals('http://acairns.co.uk', $item->resolved_url);
$this->assertEquals('Some excerpt about something', $item->excerpt);
$this->assertEquals(0, $item->is_article);
$this->assertEquals(0, $item->favorite);
$this->assertEquals(0, $item->status);
$this->assertEquals(0, $item->time_read);
$this->assertEquals(0, $item->time_favorited);
$this->assertEquals(0, $item->sort_id);
$this->assertEquals(0, $item->is_index);
$this->assertEquals(0, $item->has_video);
$this->assertEquals(0, $item->has_image);
$this->assertEquals(123, $item->word_count);
}
作者:sajar
项目:sajari-sdk-ph
/**
* Determine an exception code from the given response, exception data and
* JSON body.
*
* @param Response $response
* @param array $data
* @param array $json
*
* @return string|null
*/
private function determineCode(Response $response, array $data, array $json)
{
if (409 === $response->getStatusCode()) {
return 'DocumentAlreadyExists';
}
return $this->determineCodeFromErrors($data['errors']);
}
作者:arthurwayn
项目:ovh-sdk-ph
public function debug()
{
$r = new Response();
var_dump($r->getReasonPhrase());
$req = new Request();
$req->getPath();
}
作者:romainneutro
项目:aws-sdk-ph
/**
* {@inheritdoc}
*/
protected function getDelay($retries, RequestInterface $request, Response $response = null, HttpException $e = null)
{
if ($response && $response->isClientError()) {
$parts = $this->parser->parse($response);
return $parts['code'] == 'ProvisionedThroughputExceededException' || $parts['code'] == 'ThrottlingException' ? true : null;
}
}
作者:alnutil
项目:saucelabs_clien
public static function getApiLimit(Response $response)
{
$remainingCalls = $response->getHeader('X-RateLimit-Remaining');
if (null !== $remainingCalls && 1 > $remainingCalls) {
throw new ApiLimitExceedException($remainingCalls);
}
}
作者:javihgi
项目:genderize-io-clien
/**
* Tests getRateReset method
*/
public function testRateReset()
{
$response = new Response(200);
$response->setHeader('X-Rate-Reset', '100');
$client = new GenderizeClient();
$client->setLastResponse($response);
$this->assertEquals('100', $client->getRateReset());
}
作者:codesleev
项目:guard-live-reloa
public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
{
$this->log('open', $conn);
$response = new Response(200, array('Content-type' => 'text/javascript', 'Content-Length' => $this->getFilesize($request->getPath())));
$response->setBody($this->getContent($request->getPath()));
$conn->send((string) $response);
$conn->close();
}
作者:aciliainterne
项目:guzzle-bundl
private function getRequestTime(GuzzleResponse $response)
{
$time = $response->getInfo('total_time');
if (null === $time) {
$time = 0;
}
return (int) ($time * 1000);
}
作者:shopping-adventur
项目:RiakBundl
/**
* @param \Guzzle\Http\Message\Response $response
* @param array $extra
*/
public function logResponse($response, $extra = array())
{
!array_key_exists("serialization_time", $extra) && ($extra["serialization_time"] = "-");
!array_key_exists("deserialization_time", $extra) && ($extra["deserialization_time"] = "-");
!array_key_exists("search_time", $extra) && ($extra["search_time"] = "-");
!array_key_exists("method", $extra) && ($extra["method"] = "-");
$this->logger->debug(self::getProcessId() . ' ' . $extra["method"] . ' ' . $response->getInfo("url") . ' ' . $response->getInfo("total_time") . ' ' . $extra["deserialization_time"] . ' ' . $extra["serialization_time"] . ' ' . $extra["search_time"]);
}
作者:opdavie
项目:nwdrupalwebsit
/**
* Parses response into an array
*
* @param Response $response
* @return array
*/
protected function parseResponseIntoArray($response)
{
if (strpos($response->getContentType(), 'json') === false) {
parse_str($response->getBody(true), $array);
return $array;
}
return $response->json();
}
作者:skinnar
项目:FTL-
/**
* Parses additional exception information from the response headers
*
* @param RequestInterface $request Request that was issued
* @param Response $response The response from the request
* @param array $data The current set of exception data
*/
protected function parseHeaders(RequestInterface $request, Response $response, array &$data)
{
$data['message'] = $response->getStatusCode() . ' ' . $response->getReasonPhrase();
if ($requestId = $response->getHeader('x-amz-request-id')) {
$data['request_id'] = $requestId;
$data['message'] .= " (Request-ID: {$requestId})";
}
}
作者:huhugo
项目:ss
/**
* Factory method that allows for easy instantiation from a Response object.
*
* @param Response $response
* @param AbstractService $service
* @return static
*/
public static function fromResponse(Response $response, AbstractService $service)
{
$object = new static($service);
if (null !== ($headers = $response->getHeaders())) {
$object->setMetadata($headers, true);
}
return $object;
}
作者:RuslanZavack
项目:JiraApiBundl
/**
* Get response as an array.
*
* @return array
*/
private function getResponseAsArray()
{
$this->result = $this->response->json();
if ($this->responseHasErrors()) {
return false;
}
return $this->result;
}
作者:cpliaka
项目:magento-client-ph
/**
* Factory method to create a new Oauth exception.
*
* @param RequestInterface $request
* @param Response $response
*
* @return OauthException
*/
public static function factory(RequestInterface $request, Response $response)
{
$message = 'Client error response' . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
$e = new static($message);
$e->setResponse($response);
$e->setRequest($request);
return $e;
}
作者:unkerro
项目:Budabo
/**
* @param Guzzle\Http\Message\RequestInterface
* @return Guzzle\Http\Message\Response
*/
public function handshake(RequestInterface $request)
{
$body = $this->sign($request->getHeader('Sec-WebSocket-Key1', true), $request->getHeader('Sec-WebSocket-Key2', true), (string) $request->getBody());
$headers = array('Upgrade' => 'WebSocket', 'Connection' => 'Upgrade', 'Sec-WebSocket-Origin' => $request->getHeader('Origin', true), 'Sec-WebSocket-Location' => 'ws://' . $request->getHeader('Host', true) . $request->getPath());
$response = new Response(101, $headers, $body);
$response->setStatus(101, 'WebSocket Protocol Handshake');
return $response;
}