summaryrefslogtreecommitdiff
path: root/includes/libs/virtualrest/VirtualRESTServiceClient.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/libs/virtualrest/VirtualRESTServiceClient.php')
-rw-r--r--includes/libs/virtualrest/VirtualRESTServiceClient.php31
1 files changed, 18 insertions, 13 deletions
diff --git a/includes/libs/virtualrest/VirtualRESTServiceClient.php b/includes/libs/virtualrest/VirtualRESTServiceClient.php
index 2d21d3cf..e8bb38d8 100644
--- a/includes/libs/virtualrest/VirtualRESTServiceClient.php
+++ b/includes/libs/virtualrest/VirtualRESTServiceClient.php
@@ -125,17 +125,17 @@ class VirtualRESTServiceClient {
* - reason : HTTP response reason (empty if there was a serious cURL error)
* - headers : <header name/value associative array>
* - body : HTTP response body or resource (if "stream" was set)
- * - err : Any cURL error string
+ * - error : Any cURL error string
* The map also stores integer-indexed copies of these values. This lets callers do:
* <code>
* list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $client->run( $req );
* </code>
- * @param array $req Virtual HTTP request array
+ * @param array $req Virtual HTTP request maps
* @return array Response array for request
*/
public function run( array $req ) {
- $req = $this->runMulti( array( $req ) );
- return $req[0]['response'];
+ $responses = $this->runMulti( array( $req ) );
+ return $responses[0];
}
/**
@@ -146,14 +146,15 @@ class VirtualRESTServiceClient {
* - reason : HTTP response reason (empty if there was a serious cURL error)
* - headers : <header name/value associative array>
* - body : HTTP response body or resource (if "stream" was set)
- * - err : Any cURL error string
+ * - error : Any cURL error string
* The map also stores integer-indexed copies of these values. This lets callers do:
- * <code>
- * list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $responses[0];
+ * <code>
+ * list( $rcode, $rdesc, $rhdrs, $rbody, $rerr ) = $responses[0];
* </code>
*
- * @param array $req Map of Virtual HTTP request arrays
+ * @param array $reqs Map of Virtual HTTP request maps
* @return array $reqs Map of corresponding response values with the same keys/order
+ * @throws Exception
*/
public function runMulti( array $reqs ) {
foreach ( $reqs as $index => &$req ) {
@@ -207,6 +208,9 @@ class VirtualRESTServiceClient {
if ( ++$rounds > 5 ) { // sanity
throw new Exception( "Too many replacement rounds detected. Aborting." );
}
+ // Track requests executed this round that have a prefix/service.
+ // Note that this also includes requests where 'response' was forced.
+ $checkReqIndexesByPrefix = array();
// Resolve the virtual URLs valid and qualified HTTP(S) URLs
// and add any required authentication headers for the backend.
// Services can also replace requests with new ones, either to
@@ -219,7 +223,7 @@ class VirtualRESTServiceClient {
if ( isset( $servReqs[$index] ) || isset( $origPending[$index] ) ) {
// A current or original request which was not modified
} else {
- // Replacement requests with pre-set responses should not execute
+ // Replacement request that will convert to original requests
$newReplaceReqsByService[$prefix][$index] = $req;
}
if ( isset( $req['response'] ) ) {
@@ -231,6 +235,7 @@ class VirtualRESTServiceClient {
// Original or mangled request included
$executeReqs[$index] = $req;
}
+ $checkReqIndexesByPrefix[$prefix][$index] = 1;
}
}
// Update index of requests to inspect for replacement
@@ -245,12 +250,12 @@ class VirtualRESTServiceClient {
// defer the original or to set a proxy response to the original.
// Any replacement requests executed above will need to be replaced
// with new requests (eventually the original). The responses can be
- // forced instead of having the request sent over the wire.
+ // forced by setting 'response' rather than actually be sent over the wire.
$newReplaceReqsByService = array();
- foreach ( $replaceReqsByService as $prefix => $servReqs ) {
+ foreach ( $checkReqIndexesByPrefix as $prefix => $servReqIndexes ) {
$service = $this->instances[$prefix];
- // Only the request copies stored in $doneReqs actually have the response
- $servReqs = array_intersect_key( $doneReqs, $servReqs );
+ // $doneReqs actually has the requests (with 'response' set)
+ $servReqs = array_intersect_key( $doneReqs, $servReqIndexes );
foreach ( $service->onResponses( $servReqs, $idFunc ) as $index => $req ) {
// Services use unique IDs for replacement requests
if ( isset( $servReqs[$index] ) || isset( $origPending[$index] ) ) {