"); /** * Handles the gadget.io.makeRequest requests */ class MakeRequestHandler extends ProxyBase { /** * Constructor. * * @param GadgetContext $context Current rendering context */ public function __construct(GadgetContext $context) { $this->context = $context; $makeRequestClass = Config::get('makerequest_class'); $this->makeRequest = new $makeRequestClass(); } /** * Fetches content and echoes it in JSON format * * @param MakeRequestOptions $params The request configuration. */ public function fetchJson(MakeRequestOptions $params) { $result = $this->makeRequest->fetch($this->context, $params); $responseArray = array( 'rc' => (int)$result->getHttpCode(), 'body' => $result->getResponseContent(), 'headers' => $this->makeRequest->cleanResponseHeaders($result->getResponseHeaders()) ); $responseArray = array_merge($responseArray, $result->getMetadatas()); $json = array($params->getHref() => $responseArray); $json = json_encode($json); $output = UNPARSEABLE_CRUFT . $json; if ($responseArray['rc'] == 200) { // only set caching headers if the result was 'OK' $this->setCachingHeaders(); } if (!Config::get('debug')) { header('Content-Type: application/json; charset="UTF-8"'); header('Content-Disposition: attachment;filename=p.txt'); } echo $output; } }