/** * Determines if this response needs to be decoded. * * @param ehough_shortstop_api_HttpResponse $response The HTTP response. * * @return boolean True if this response should be decoded. False otherwise. */ public final function needsToBeDecoded(ehough_shortstop_api_HttpResponse $response) { $entity = $response->getEntity(); $isDebugEnabled = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($entity === null) { if ($isDebugEnabled) { $this->_logger->debug('Response contains no entity'); } return false; } $content = $entity->getContent(); if ($content == '' || $content == null) { if ($isDebugEnabled) { $this->_logger->debug('Response entity contains no content'); } return false; } $expectedHeaderName = $this->getHeaderName(); $actualHeaderValue = $response->getHeaderValue($expectedHeaderName); if ($actualHeaderValue === null) { if ($isDebugEnabled) { $this->_logger->debug(sprintf('Response does not contain %s header. No need to decode.', $expectedHeaderName)); } return false; } if ($isDebugEnabled) { $this->_logger->debug(sprintf('Response contains %s header. Will attempt decode.', $expectedHeaderName)); } return true; }
private function _canHandle(ehough_shortstop_api_HttpRequest $request, ehough_shortstop_api_HttpResponse $response) { $url = $request->getUrl(); $host = $url->getHost(); if (!tubepress_impl_util_StringUtils::endsWith($host, 'youtube.com')) { return false; } $contentType = $response->getHeaderValue('Content-Type'); $entity = $response->getEntity(); return $entity && $contentType === 'application/vnd.google.gdata.error+xml'; }
private function _assignEntityToResponse($body, ehough_shortstop_api_HttpResponse $response, $debugging) { if ($debugging) { $this->getLogger()->debug('Assigning (possibly empty) entity to response'); } $entity = new ehough_shortstop_api_HttpEntity(); $entity->setContent($body); $entity->setContentLength(strlen($body)); $contentType = $response->getHeaderValue(ehough_shortstop_api_HttpResponse::HTTP_HEADER_CONTENT_TYPE); if ($contentType !== null) { $entity->setContentType($contentType); } $response->setEntity($entity); }