summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuuso Lapinlampi <wub@partyvan.eu>2015-09-29 23:53:01 +0200
committerJuuso Lapinlampi <wub@partyvan.eu>2015-09-29 23:53:01 +0200
commitfb23dde10af35eea3b0f0b14459630305618ac3a (patch)
tree3eb46e96cabcc93ee6823b093096194a7ad20bcc
parent2ca5b6b743487477fdaf045a7d4abb605780a300 (diff)
Remove default undefined behavior from Response class
Let's say some user decides to use output "xml". Unexpectedly, the user would instead receive JSON output. This is undefined behavior in its own way and violates the principle of least surprise. Problems could arise if we added "xml" later with actual application/xml or text/xml content. Right now upload.php overrides an empty output argument to json instead, so this seems safe to do. Any non-existent output will now return a 400 Bad Request error.
-rwxr-xr-xstatic/classes/Response.class.php12
1 files changed, 8 insertions, 4 deletions
diff --git a/static/classes/Response.class.php b/static/classes/Response.class.php
index 25d101c..cb34ab4 100755
--- a/static/classes/Response.class.php
+++ b/static/classes/Response.class.php
@@ -45,9 +45,13 @@ class Response
header('Content-Type: text/plain; charset=UTF-8');
$this->type = $response_type;
break;
- default:
+ case 'json':
header('Content-Type: application/json; charset=UTF-8');
- $this->type = 'json';
+ $this->type = $response_type;
+ break;
+ default:
+ http_response_code(400);
+ echo 'Invalid response type. Valid options are: csv, html, text, json.';
break;
}
}
@@ -66,7 +70,7 @@ class Response
case 'text':
$response = $this->text_error($code, $desc);
break;
- default:
+ case 'json':
$response = $this->json_error($code, $desc);
break;
}
@@ -89,7 +93,7 @@ class Response
case 'text':
$response = $this->text_success($files);
break;
- default:
+ case 'json':
$response = $this->json_success($files);
break;
}