You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shindig.apache.org by ch...@apache.org on 2009/07/14 15:40:07 UTC
svn commit: r793899 - in /incubator/shindig/trunk/php/src:
common/RemoteContentRequest.php common/sample/BasicRemoteContent.php
common/sample/BasicRemoteContentFetcher.php gadgets/ProxyHandler.php
Author: chabotc
Date: Tue Jul 14 13:40:07 2009
New Revision: 793899
URL: http://svn.apache.org/viewvc?rev=793899&view=rev
Log:
Use a matching http error code on failed proxy requests. Since curl doesnt return the http status code message I've had to add a lookup table to the remote content fetcher
Modified:
incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
incubator/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php
incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=793899&r1=793898&r2=793899&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Tue Jul 14 13:40:07 2009
@@ -32,6 +32,7 @@
private $responseHeaders = array();
private $metadata = array();
private $httpCode = false;
+ private $httpCodeMsg = '';
private $contentType = null;
private $created;
private $refreshInterval;
@@ -146,6 +147,10 @@
return $this->httpCode;
}
+ public function getHttpCodeMsg() {
+ return $this->httpCodeMsg;
+ }
+
public function getResponseContent() {
return $this->responseContent;
}
@@ -215,6 +220,10 @@
$this->httpCode = intval($code);
}
+ public function setHttpCodeMsg($msg) {
+ $this->httpCodeMsg = $msg;
+ }
+
public function setResponseContent($content) {
$this->responseContent = $content;
}
Modified: incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php?rev=793899&r1=793898&r2=793899&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php (original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicRemoteContent.php Tue Jul 14 13:40:07 2009
@@ -151,7 +151,7 @@
$ignoreCache = $originalRequest->getOptions()->ignoreCache;
if (($this->cachePostRequest || ! $request->isPost()) && ! $ignoreCache) {
$ttl = Config::get('cache_time');
- if ($request->getHttpCode() == '200') {
+ if ((int)$request->getHttpCode() == 200) {
// Got a 200 OK response, calculate the TTL to use for caching it
if (($expires = $request->getResponseHeader('Expires')) != null) {
// prefer to use the servers notion of the time since there could be a clock-skew, but otherwise use our own
Modified: incubator/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php?rev=793899&r1=793898&r2=793899&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php (original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicRemoteContentFetcher.php Tue Jul 14 13:40:07 2009
@@ -107,6 +107,7 @@
$httpCode = '404';
}
$request->setHttpCode($httpCode);
+ $request->setHttpCodeMsg($this->resolveHttpCode($httpCode));
$request->setContentType($contentType);
$request->setResponseHeaders($parsedHeaders);
$request->setResponseContent($body);
@@ -114,6 +115,59 @@
}
/**
+ * Misc function to resolve http status codes to a matching http code message
+ * since curl strips those, but we do need'm in the proxy handler
+ * @param $httpCode
+ * @return string
+ */
+ private function resolveHttpCode($httpCode) {
+ switch ((int)$httpCode) {
+ case 100: return "Continue";
+ case 101: return "Switching Protocols";
+ case 200: return "OK";
+ case 201: return "Created";
+ case 202: return "Accepted";
+ case 203: return "Non-Authoritative Information";
+ case 204: return "No Content";
+ case 205: return "Reset Content";
+ case 206: return "Partial Content";
+ case 300: return "Multiple Choices";
+ case 301: return "Moved Permanently";
+ case 302: return "Found";
+ case 303: return "See Other";
+ case 304: return "Not Modified";
+ case 305: return "Use Proxy";
+ case 306: return "(Unused)";
+ case 307: return "Temporary Redirect";
+ case 400: return "Bad Request";
+ case 401: return "Unauthorized";
+ case 402: return "Payment Required";
+ case 403: return "Forbidden";
+ case 404: return "Not Found";
+ case 405: return "Method Not Allowed";
+ case 406: return "Not Acceptable";
+ case 407: return "Proxy Authentication Required";
+ case 408: return "Request Timeout";
+ case 409: return "Conflict";
+ case 410: return "Gone";
+ case 411: return "Length Required";
+ case 412: return "Precondition Failed";
+ case 413: return "Request Entity Too Large";
+ case 414: return "Request-URI Too Long";
+ case 415: return "Unsupported Media Type";
+ case 416: return "Requested Range Not Satisfiable";
+ case 417: return "Expectation Failed";
+ case 500: return "Internal Server Error";
+ case 501: return "Not Implemented";
+ case 502: return "Bad Gateway";
+ case 503: return "Service Unavailable";
+ case 504: return "Gateway Timeout";
+ case 505: return "HTTP Version Not Supported";
+ default : return "Unknown Error";
+ }
+ }
+
+ /**
* Sets the headers and post body for the request if they are specified
*
* @param RemoteContentRequest $request
Modified: incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php?rev=793899&r1=793898&r2=793899&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/ProxyHandler.php Tue Jul 14 13:40:07 2009
@@ -76,6 +76,7 @@
header('HTTP/1.0 304 Not Modified', true);
header('Content-Length: 0', true);
} else {
+ header("HTTP/1.1 $httpCode ".$result->getHttpCodeMsg());
// then echo the content
echo $result->getResponseContent();
}