function mfForResponse(Guzzle\Http\Message\Response $resp) { $html = $resp->getBody(true); $host = parse_url($resp->getEffectiveUrl(), PHP_URL_HOST); if ($host == 'twitter.com') { return Mf2\Shim\parseTwitter($html, $resp->getEffectiveUrl()); } elseif ($host == 'facebook.com') { return Mf2\Shim\parseFacebook($html, $resp->getEffectiveUrl()); } else { return Mf2\parse($html, $resp->getEffectiveUrl()); } }
private function resolveRequest(\Guzzle\Http\Message\Request $request) { try { $this->lastResponse = $request->send(); } catch (\Guzzle\Http\Exception\TooManyRedirectsException $tooManyRedirectsException) { if ($this->hasRequestHistory($request)) { $this->lastResponse = $this->getRequestHistory($request)->getLastResponse(); } else { return $request->getUrl(); } } catch (\Guzzle\Http\Exception\BadResponseException $badResponseException) { if ($this->getConfiguration()->getRetryWithUrlEncodingDisabled() && !$this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) { $this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(true); return $this->resolveRequest($this->deEncodeRequestUrl($request)); } else { $this->lastResponse = $badResponseException->getResponse(); } } if ($this->getConfiguration()->getHasRetriedWithUrlEncodingDisabled()) { $this->getConfiguration()->setHasRetriedWithUrlEncodingDisabled(false); } if ($this->getConfiguration()->getFollowMetaRedirects()) { $metaRedirectUrl = $this->getMetaRedirectUrlFromLastResponse(); if (!is_null($metaRedirectUrl) && !$this->isLastResponseUrl($metaRedirectUrl)) { return $this->resolve($metaRedirectUrl); } } return $this->lastResponse->getEffectiveUrl(); }
/** * Create a tailored PUT request for each file * * @param Response $response * @return \Guzzle\Http\Message\EntityEnclosingRequestInterface */ protected function createPutRequest(Response $response) { $segments = Url::factory($response->getEffectiveUrl())->getPathSegments(); $name = end($segments); // Retrieve content and metadata $file = $this->newContainer->dataObject()->setName($name); $file->setMetadata($response->getHeaders(), true); return $this->getClient()->put($file->getUrl(), $file::stockHeaders($file->getMetadata()->toArray()), $response->getBody()); }
/** * Construct a TransferPart from a HTTP response delivered by the API. * * @param Response $response * @param int $partNumber * @return TransferPart */ public static function fromResponse(Response $response, $partNumber = 1) { $responseUri = Url::factory($response->getEffectiveUrl()); $object = new self(); $object->setPartNumber($partNumber)->setContentLength($response->getHeader(Header::CONTENT_LENGTH))->setETag($response->getHeader(Header::ETAG))->setPath($responseUri->getPath()); return $object; }
/** * {@inheritdoc} */ public function getEffectiveUrl() { return $this->response->getEffectiveUrl(); }
function pushLinksForResponse(Guzzle\Http\Message\Response $resp) { $self = null; $hubs = []; $linkHeader = $resp->getHeader('link'); if ($linkHeader instanceof Guzzle\Http\Message\Header\Link) { $links = $linkHeader->getLinks(); foreach ($links as $link) { if (strpos(" {$link['rel']} ", ' self ') !== false) { $self = $link['url']; } if (strpos(" {$link['rel']} ", ' hub ') !== false) { $hubs[] = $link['url']; } } } if (strpos($resp->getContentType(), 'html') !== false) { $mf = Mf2\parse($resp->getBody(true), $resp->getEffectiveUrl()); if (!empty($mf['rels']['hub'])) { $hubs = array_merge($hubs, $mf['rels']['hub']); } if (!empty($mf['rels']['self']) and $self === null) { $self = $mf['rels']['self'][0]; } } return ['self' => $self, 'hub' => $hubs]; }