You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2008/05/21 19:26:38 UTC
svn commit: r658771 -
/incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php
Author: chabotc
Date: Wed May 21 10:26:38 2008
New Revision: 658771
URL: http://svn.apache.org/viewvc?rev=658771&view=rev
Log:
Only instance the signingFetcherFactory if authz is set, also handle exceptions more gracefully with a 500 internal server error
Modified:
incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php
Modified: incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php?rev=658771&r1=658770&r2=658771&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/http/ProxyServlet.php Wed May 21 10:26:38 2008
@@ -33,31 +33,40 @@
public function doGet()
{
- $this->noHeaders = true;
- $context = new GadgetContext('GADGET');
- // those should be doable in one statement, but php seems to still evauluate the second ? and : pair,
- // so throws an error about undefined index on post, even though it found it in get ... odd bug
- $url = isset($_GET['url']) ? $_GET['url'] : false;
- if (! $url) {
- $url = isset($_POST['url']) ? $_POST['url'] : false;
- }
- $url = urldecode($url);
- $method = isset($_GET['httpMethod']) ? $_GET['httpMethod'] : false;
- if (! $method) {
- $method = isset($_POST['httpMethod']) ? $_POST['httpMethod'] : 'GET';
- }
- if (! $url) {
- header("HTTP/1.0 400 Bad Request", true);
- echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
- }
- $gadgetSigner = Config::get('security_token_signer');
- $gadgetSigner = new $gadgetSigner();
- $signingFetcherFactory = new SigningFetcherFactory(Config::get("private_key_file"));
- $proxyHandler = new ProxyHandler($context, $signingFetcherFactory);
- if (! empty($_GET['output']) && $_GET['output'] == 'js') {
- $proxyHandler->fetchJson($url, $gadgetSigner, $method);
- } else {
- $proxyHandler->fetch($url, $gadgetSigner, $method);
+ try {
+ $this->noHeaders = true;
+ $context = new GadgetContext('GADGET');
+ // those should be doable in one statement, but php seems to still evauluate the second ? and : pair,
+ // so throws an error about undefined index on post, even though it found it in get ... odd bug
+ $url = isset($_GET['url']) ? $_GET['url'] : false;
+ if (! $url) {
+ $url = isset($_POST['url']) ? $_POST['url'] : false;
+ }
+ $url = urldecode($url);
+ $method = isset($_GET['httpMethod']) ? $_GET['httpMethod'] : false;
+ if (! $method) {
+ $method = isset($_POST['httpMethod']) ? $_POST['httpMethod'] : 'GET';
+ }
+ if (! $url) {
+ header("HTTP/1.0 400 Bad Request", true);
+ echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
+ }
+ $signingFetcherFactory = false;
+ if (empty($_GET['authz'])) {
+ $gadgetSigner = Config::get('security_token_signer');
+ $gadgetSigner = new $gadgetSigner();
+ $signingFetcherFactory = new SigningFetcherFactory(Config::get("private_key_file"));
+ }
+ $proxyHandler = new ProxyHandler($context, $signingFetcherFactory);
+ if (! empty($_GET['output']) && $_GET['output'] == 'js') {
+ $proxyHandler->fetchJson($url, $gadgetSigner, $method);
+ } else {
+ $proxyHandler->fetch($url, $gadgetSigner, $method);
+ }
+ } catch (Exception $e) {
+ // catch all exceptions and give a 500 server error
+ header("HTTP/1.0 500 Internal Server Error");
+ echo "<h1>Internal server error</h1><p>".$e->getMessage()."</p>";
}
}