53 $mparams = array_merge( [
55 'url' =>
'http://localhost:7231/',
56 'domain' =>
'localhost',
58 'forwardCookies' =>
false,
60 'parsoidCompat' =>
false,
64 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
65 $mparams[
'url'] .=
'/';
70 $mparams[
'domain'] = preg_replace(
71 '/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
75 parent::__construct( $mparams );
82 public function onRequests( array $reqs, Closure $idGenFunc ) {
83 if ( $this->params[
'parsoidCompat'] ) {
88 foreach ( $reqs as $key => $req ) {
89 if ( $this->params[
'fixedUrl'] ) {
90 $version = explode(
'/', $req[
'url'] )[1];
92 str_replace(
'#version#', $version, $this->params[
'url'] ) .
93 preg_replace(
'#^local/v./#',
'', $req[
'url'] );
96 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
98 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
102 if ( $this->params[
'HTTPProxy'] ) {
103 $req[
'proxy'] = $this->params[
'HTTPProxy'];
105 if ( $this->params[
'timeout'] !=
null ) {
106 $req[
'reqTimeout'] = $this->params[
'timeout'];
108 if ( $this->params[
'forwardCookies'] ) {
109 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
111 $result[$key] = $req;
126 foreach ( $reqs as $key => $req ) {
127 $version = explode(
'/', $req[
'url'] )[1];
128 if ( $version ===
'v3' ) {
131 throw new Exception(
"Only Parsoid v3 is supported." );
157 $parts = explode(
'/', $req[
'url'] );
166 if ( $targetWiki !==
'local' ) {
167 throw new Exception(
"Only 'local' target wiki is currently supported" );
168 } elseif ( $version !==
'v3' ) {
169 throw new Exception(
"Version mismatch: should not happen." );
172 $req[
'url'] = preg_replace(
'#^local/v3/#', $this->params[
'domain'] .
'/v1/', $req[
'url'] );
174 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
176 if ( $this->params[
'HTTPProxy'] ) {
177 $req[
'proxy'] = $this->params[
'HTTPProxy'];
179 if ( $this->params[
'timeout'] !=
null ) {
180 $req[
'reqTimeout'] = $this->params[
'timeout'];
182 if ( $this->params[
'forwardCookies'] ) {
183 $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.