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/08/02 11:51:45 UTC
svn commit: r800014 -
/incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php
Author: chabotc
Date: Sun Aug 2 09:51:44 2009
New Revision: 800014
URL: http://svn.apache.org/viewvc?rev=800014&view=rev
Log:
Make the os:HttpRequest response format spec compliant (i think)
Modified:
incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php
Modified: incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php?rev=800014&r1=800013&r2=800014&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php (original)
+++ incubator/shindig/trunk/php/src/gadgets/templates/DataPipelining.php Sun Aug 2 09:51:44 2009
@@ -95,7 +95,7 @@
if (($resolved = self::resolveRequest($request, $result)) !== false) {
$requestQueue[] = $resolved;
unset($dataPipeliningRequests[$key]);
- }
+ }
}
if (count($requestQueue)) {
$returnedResults = self::performRequests($requestQueue, $context);
@@ -198,13 +198,41 @@
$basicRemoteContent = new BasicRemoteContent();
$resps = $basicRemoteContent->multiFetch($requestQueue);
foreach ($resps as $response) {
- // strip out the UNPARSEABLE_CRUFT (see makeRequestHandler.php) on assigning the body
+ //FIXME: this isn't completely correct yet since this picks up the status code and headers
+ // as they are returned by the makeRequest handler and not the ones from the original request
+
$url = $response->getNotSignedUrl();
$id = $httpRequests[$url]['id'];
+ // strip out the UNPARSEABLE_CRUFT (see makeRequestHandler.php) on assigning the body
$resp = json_decode(str_replace("throw 1; < don't be evil' >", '', $response->getResponseContent()), true);
if (is_array($resp)) {
- $toAdd[$id] = array('id' => $id, 'data' => $httpRequests[$url]['format'] == 'json' ? json_decode($resp[$url]['body'], true) : $resp[$url]['body']);
- $decodedResponse = array_merge($toAdd, $decodedResponse);
+ $statusCode = $response->getHttpCode();
+ $statusCodeMessage = $response->getHttpCodeMsg();
+ $headers = $response->getHeaders();
+ if (intval($statusCode) == 200) {
+ $content = $httpRequests[$url]['format'] == 'json' ? json_decode($resp[$url]['body'], true) : $resp[$url]['body'];
+ $toAdd = array(
+ 'result' => array(
+ 'content' => $content,
+ 'status' => $statusCode,
+ 'headers' => $headers
+ )
+ );
+ } else {
+ $content = $resp[$url]['body'];
+ $toAdd = array(
+ 'error' => array(
+ 'code' => $statusCode,
+ 'message' => $statusCodeMessage,
+ 'data' => array(
+ 'content' => $content,
+ 'headers' => $headers
+ )
+ )
+ );
+ }
+ //$toAdd[$id] = array('id' => $id, 'data' => $httpRequests[$url]['format'] == 'json' ? json_decode($resp[$url]['body'], true) : $resp[$url]['body']);
+ $decodedResponse[] = array('id' => $id, 'data' => $toAdd);
}
}
}
@@ -231,7 +259,7 @@
try {
$expressionResult = ExpressionParser::evaluate($expression, $dataContext);
$request[$key] = str_replace($toReplace, $expressionResult, $request[$key]);
- } catch (ExpressionException $e) {
+ } catch (Exception $e) {
// ignore, maybe on the next pass we can resolve this
return false;
}