diff options
author | elij <elij.mx@gmail.com> | 2011-05-28 23:14:34 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2011-05-29 15:57:45 +0200 |
commit | 4a24bca069edc2830fc17ab27ba54560435b778b (patch) | |
tree | db2dc27e84707495ec4a8576ea26264d64ca0a95 /web/html | |
parent | 0df6d7b4e7e3735365921ef494ed66738cf53a6b (diff) | |
download | aur-4a24bca069edc2830fc17ab27ba54560435b778b.tar.gz aur-4a24bca069edc2830fc17ab27ba54560435b778b.tar.xz |
restructure the html/rpc.php endpoint
- move request_method test to the top, and catch other request types
(HEAD, PUT, etc)
- change how html output is handled. instead of building a string, just
output the html
- set appropriate response header for incorrect request_method.
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web/html')
-rw-r--r-- | web/html/rpc.php | 61 |
1 files changed, 33 insertions, 28 deletions
diff --git a/web/html/rpc.php b/web/html/rpc.php index 1a9ca34b..b2c244be 100644 --- a/web/html/rpc.php +++ b/web/html/rpc.php @@ -1,36 +1,41 @@ <?php - set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); - include_once("aurjson.class.php"); -if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) { - if ( isset($_GET['type']) ) { - $rpc_o = new AurJSON(); - echo $rpc_o->handle($_GET); - } - else { - // dump a simple usage output for people to use. - // this could be moved to an api doc in the future, or generated from - // the AurJSON class directly with phpdoc. For now though, just putting it here. - echo '<html><body>'; - echo 'The methods currently allowed are: <br />'; - echo '<ul>'; - echo '<li>search</li>'; - echo '<li>info</li>'; - echo '<li>multiinfo</li>'; - echo '<li>msearch</li>'; - echo '</ul><br />'; - echo 'Each method requires the following HTTP GET syntax:<br />'; - echo ' type=<i>methodname</i>&arg=<i>data</i> <br /><br />'; - echo 'Where <i>methodname</i> is the name of an allowed method, and <i>data</i> is the argument to the call.<br />'; - echo '<br />'; - echo 'If you need jsonp type callback specification, you can provide an additional variable <i>callback</i>.<br />'; - echo 'Example URL: <br /> http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103'; - echo '</body></html>'; - } +if ( $_SERVER['REQUEST_METHOD'] != 'GET' ) { + header('HTTP/1.1 405 Method Not Allowed'); + exit(); +} + +if ( isset($_GET['type']) ) { + $rpc_o = new AurJSON(); + echo $rpc_o->handle($_GET); } else { - echo 'POST NOT SUPPORTED'; + // dump a simple usage output for people to use. + // this could be moved to an api doc in the future, or generated from + // the AurJSON class directly with phpdoc. For now though, just putting it + // here. +?> +<html><body> +The methods currently allowed are: <br /> +<ul> + <li>search</li> + <li>info</li> + <li>multiinfo</li> + <li>msearch</li> +</ul> <br /> +Each method requires the following HTTP GET syntax: <br /> + type=<i>methodname</i>&arg=<i>data</i> +<br /><br /> +Where <i>methodname</i> is the name of an allowed method, and <i>data</i> is the argument to the call. +<br /><br /> +If you need jsonp type callback specification, you can provide an additional variable <i>callback</i>. +<br /> +Example URL: <br /> + http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103 +</body></html> +<?php +// close if statement } ?> |