/** * Decodes transfer encoded data in the entity body of this response and re-assigns * the decoded entity to the response. * * @param org_tubepress_api_http_HttpResponse $response The HTTP response. * * @return void */ function decode(org_tubepress_api_http_HttpResponse $response) { $ioc = org_tubepress_impl_ioc_IocContainer::getInstance(); $commands = $this->getArrayOfCommandNames(); $chain = $ioc->get(org_tubepress_spi_patterns_cor_Chain::_); $context = $chain->createContextInstance(); $context->response = $response; $status = $chain->execute($context, $commands); if ($status === false) { throw new Exception('Unable to decode HTTP response'); } $entity = $response->getEntity(); $entity->setContent($context->decoded); $entity->setContentLength(strlen($context->decoded)); $contentType = $response->getHeaderValue(org_tubepress_api_http_HttpMessage::HTTP_HEADER_CONTENT_TYPE); if ($contentType !== null) { $entity->setContentType($contentType); } $response->setEntity($entity); }
private function _assignEntityToResponse($body, org_tubepress_api_http_HttpResponse $response, org_tubepress_api_http_HttpRequest $request) { org_tubepress_impl_log_Log::log($this->logPrefix(), 'Assigning (possibly empty) entity to response'); $entity = new org_tubepress_api_http_HttpEntity(); $entity->setContent($body); $entity->setContentLength(strlen($body)); $contentType = $response->getHeaderValue(org_tubepress_api_http_HttpResponse::HTTP_HEADER_CONTENT_TYPE); if ($contentType !== null) { $entity->setContentType($contentType); } $response->setEntity($entity); }