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>
This commit is contained in:
elij 2011-05-28 14:14:34 -07:00 committed by Lukas Fleischer
parent 0df6d7b4e7
commit 4a24bca069

View file

@ -1,10 +1,12 @@
<?php <?php
set_include_path(get_include_path() . PATH_SEPARATOR . '../lib'); set_include_path(get_include_path() . PATH_SEPARATOR . '../lib');
include_once("aurjson.class.php"); include_once("aurjson.class.php");
if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) { if ( $_SERVER['REQUEST_METHOD'] != 'GET' ) {
header('HTTP/1.1 405 Method Not Allowed');
exit();
}
if ( isset($_GET['type']) ) { if ( isset($_GET['type']) ) {
$rpc_o = new AurJSON(); $rpc_o = new AurJSON();
echo $rpc_o->handle($_GET); echo $rpc_o->handle($_GET);
@ -12,25 +14,28 @@ if ( $_SERVER['REQUEST_METHOD'] == 'GET' ) {
else { else {
// dump a simple usage output for people to use. // dump a simple usage output for people to use.
// this could be moved to an api doc in the future, or generated from // 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. // the AurJSON class directly with phpdoc. For now though, just putting it
echo '<html><body>'; // here.
echo 'The methods currently allowed are: <br />'; ?>
echo '<ul>'; <html><body>
echo '<li>search</li>'; The methods currently allowed are: <br />
echo '<li>info</li>'; <ul>
echo '<li>multiinfo</li>'; <li>search</li>
echo '<li>msearch</li>'; <li>info</li>
echo '</ul><br />'; <li>multiinfo</li>
echo 'Each method requires the following HTTP GET syntax:<br />'; <li>msearch</li>
echo '&nbsp;&nbsp; type=<i>methodname</i>&arg=<i>data</i> <br /><br />'; </ul> <br />
echo 'Where <i>methodname</i> is the name of an allowed method, and <i>data</i> is the argument to the call.<br />'; Each method requires the following HTTP GET syntax: <br />
echo '<br />'; &nbsp;&nbsp; type=<i>methodname</i>&arg=<i>data</i>
echo 'If you need jsonp type callback specification, you can provide an additional variable <i>callback</i>.<br />'; <br /><br />
echo 'Example URL: <br />&nbsp;&nbsp; http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103'; Where <i>methodname</i> is the name of an allowed method, and <i>data</i> is the argument to the call.
echo '</body></html>'; <br /><br />
} If you need jsonp type callback specification, you can provide an additional variable <i>callback</i>.
} <br />
else { Example URL: <br />
echo 'POST NOT SUPPORTED'; &nbsp;&nbsp; http://aur-url/rpc.php?type=search&arg=foobar&callback=jsonp1192244621103
</body></html>
<?php
// close if statement
} }
?> ?>