mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix content-type when sending jsonp
jsonp callback should have a content type of text/javascipt, since it specifies a callback function wrapping json data, and is not soley json data. Signed-off-by: Loui Chang <louipc.ist@gmail.com>
This commit is contained in:
parent
94b1e165e1
commit
a6d5cb71a6
1 changed files with 8 additions and 4 deletions
|
@ -11,7 +11,7 @@ if (!extension_loaded('json')) {
|
||||||
include_once("aur.inc");
|
include_once("aur.inc");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class defines a remote interface for fetching data
|
* This class defines a remote interface for fetching data
|
||||||
* from the AUR using JSON formatted elements.
|
* from the AUR using JSON formatted elements.
|
||||||
* @package rpc
|
* @package rpc
|
||||||
* @subpackage classes
|
* @subpackage classes
|
||||||
|
@ -28,9 +28,6 @@ class AurJSON {
|
||||||
* @return string The JSON formatted response data.
|
* @return string The JSON formatted response data.
|
||||||
**/
|
**/
|
||||||
public function handle($http_data) {
|
public function handle($http_data) {
|
||||||
// set content type header to json
|
|
||||||
header('content-type: application/json');
|
|
||||||
|
|
||||||
// handle error states
|
// handle error states
|
||||||
if ( !isset($http_data['type']) || !isset($http_data['arg']) ) {
|
if ( !isset($http_data['type']) || !isset($http_data['arg']) ) {
|
||||||
return $this->json_error('No request type/data specified.');
|
return $this->json_error('No request type/data specified.');
|
||||||
|
@ -47,9 +44,14 @@ class AurJSON {
|
||||||
|
|
||||||
// allow rpc callback for XDomainAjax
|
// allow rpc callback for XDomainAjax
|
||||||
if ( isset($http_data['callback']) ) {
|
if ( isset($http_data['callback']) ) {
|
||||||
|
// it is more correct to send text/javascript
|
||||||
|
// content-type for jsonp-callback
|
||||||
|
header('content-type: text/javascript');
|
||||||
return $http_data['callback'] . "({$json})";
|
return $http_data['callback'] . "({$json})";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// set content type header to app/json
|
||||||
|
header('content-type: application/json');
|
||||||
return $json;
|
return $json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,6 +67,8 @@ class AurJSON {
|
||||||
* @return mixed A json formatted error response.
|
* @return mixed A json formatted error response.
|
||||||
**/
|
**/
|
||||||
private function json_error($msg){
|
private function json_error($msg){
|
||||||
|
// set content type header to app/json
|
||||||
|
header('content-type: application/json');
|
||||||
return $this->json_results('error',$msg);
|
return $this->json_results('error',$msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue