Browse Source

add query string param to pretty-print JSON output

pull/39/head
Aaron Parecki 8 years ago
parent
commit
814df605b6
1 changed files with 8 additions and 1 deletions
  1. +8
    -1
      controllers/Parse.php

+ 8
- 1
controllers/Parse.php View File

@ -7,6 +7,7 @@ use XRay\Formats;
class Parse {
public $http;
private $_pretty = false;
public function __construct() {
$this->http = new p3k\HTTP();
@ -18,7 +19,9 @@ class Parse {
$response->headers->set($k, $v);
}
$response->headers->set('Content-Type', 'application/json');
$response->setContent(json_encode($params));
$opts = JSON_UNESCAPED_SLASHES;
if($this->_pretty) $opts += JSON_PRETTY_PRINT;
$response->setContent(json_encode($params, $opts)."\n");
return $response;
}
@ -37,6 +40,10 @@ class Parse {
$this->http->max_redirects = (int)$request->get('max_redirects');
}
if($request->get('pretty')) {
$this->_pretty = true;
}
$url = $request->get('url');
if(!$url) {

Loading…
Cancel
Save