49 if ( isset(
$params[
'URL'] ) ) {
54 $mparams = array_merge( [
56 'url' =>
'http://localhost:8000/',
57 'prefix' =>
'localhost',
58 'domain' =>
'localhost',
60 'forwardCookies' =>
false,
64 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
65 $mparams[
'url'] .=
'/';
70 $mparams[
'domain'] = preg_replace(
71 '/^(https?:\/\/)?([^\/:]+?)(:\d+)?\/?$/',
75 parent::__construct( $mparams );
78 public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
80 foreach ( $reqs as $key => $req ) {
81 $parts = explode(
'/', $req[
'url'] );
92 if ( isset( $this->params[
'restbaseCompat'] ) && $this->params[
'restbaseCompat'] ) {
93 if ( $version !==
'v1' ) {
94 throw new Exception(
"Only RESTBase v1 API is supported." );
96 # Map RESTBase v1 API to Parsoid v3 API (pretty easy)
97 $req[
'url'] = preg_replace(
'#^local/v1/#',
'local/v3/', $req[
'url'] );
98 } elseif ( $version !==
'v3' ) {
99 throw new Exception(
"Only Parsoid v3 API is supported." );
101 if ( $targetWiki !==
'local' ) {
102 throw new Exception(
"Only 'local' target wiki is currently supported" );
104 if ( $reqType !==
'page' && $reqType !==
'transform' ) {
105 throw new Exception(
"Request action must be either 'page' or 'transform'" );
107 if ( $format !==
'html' && $format !==
'wikitext' ) {
108 throw new Exception(
"Request format must be either 'html' or 'wt'" );
111 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
113 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
115 if ( $this->params[
'HTTPProxy'] ) {
116 $req[
'proxy'] = $this->params[
'HTTPProxy'];
118 if ( $this->params[
'timeout'] !=
null ) {
119 $req[
'reqTimeout'] = $this->params[
'timeout'];
121 if ( $this->params[
'forwardCookies'] ) {
122 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
124 $result[$key] = $req;
Virtual HTTP service client for Parsoid.
onRequests(array $reqs, Closure $idGeneratorFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.
__construct(array $params)
Example Parsoid v3 requests: GET /local/v3/page/html/$title/{$revision}.
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
array $params
Key/value map.