53 $mparams = array_merge( [
55 'url' =>
'http://localhost:7231/',
56 'domain' =>
'localhost',
58 'forwardCookies' =>
false,
60 'parsoidCompat' =>
false,
65 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
66 $mparams[
'url'] .=
'/';
71 $mparams[
'domain'] = preg_replace(
72 '/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
77 parent::__construct( $mparams );
84 public function onRequests( array $reqs, Closure $idGenFunc ) {
85 if ( $this->params[
'parsoidCompat'] ) {
90 foreach ( $reqs as $key => $req ) {
91 if ( $this->params[
'fixedUrl'] ) {
92 $version = explode(
'/', $req[
'url'] )[1];
94 str_replace(
'#version#', $version, $this->params[
'url'] ) .
95 preg_replace(
'#^local/v./#',
'', $req[
'url'] );
98 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
100 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
104 if ( $this->params[
'HTTPProxy'] ) {
105 $req[
'proxy'] = $this->params[
'HTTPProxy'];
107 if ( $this->params[
'timeout'] !=
null ) {
108 $req[
'reqTimeout'] = $this->params[
'timeout'];
110 if ( $this->params[
'forwardCookies'] ) {
111 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
113 $result[$key] = $req;
128 foreach ( $reqs as $key => $req ) {
129 $version = explode(
'/', $req[
'url'] )[1];
130 if ( $version ===
'v3' ) {
133 throw new Exception(
"Only Parsoid v3 is supported." );
159 $parts = explode(
'/', $req[
'url'] );
168 if ( $targetWiki !==
'local' ) {
169 throw new Exception(
"Only 'local' target wiki is currently supported" );
170 } elseif ( $version !==
'v3' ) {
171 throw new Exception(
"Version mismatch: should not happen." );
174 $req[
'url'] = preg_replace(
'#^local/v3/#', $this->params[
'domain'] .
'/v1/', $req[
'url'] );
176 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
178 if ( $this->params[
'HTTPProxy'] ) {
179 $req[
'proxy'] = $this->params[
'HTTPProxy'];
181 if ( $this->params[
'timeout'] !=
null ) {
182 $req[
'reqTimeout'] = $this->params[
'timeout'];
184 if ( $this->params[
'forwardCookies'] ) {
185 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
Virtual HTTP service client for RESTBase.
onRequests(array $reqs, Closure $idGenFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.This method should mangle any of th...
onParsoidRequests(array $reqs, Closure $idGeneratorFunc)
Remaps Parsoid v3 requests to RESTBase v1 requests.
onParsoid3Request(array $req, Closure $idGeneratorFunc)
Remap a Parsoid v3 request to a RESTBase v1 request.
__construct(array $params)
Example RESTBase v1 requests: GET /local/v1/page/html/{title}{/revision} POST /local/v1/transform/htm...
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
array $params
Key/value map.