| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
use MediaWiki\MainConfigNames; |
| 22 |
use MediaWiki\MediaWikiServices; |
| 23 |
use MediaWiki\Request\WebRequest; |
| 24 |
use MediaWiki\Status\Status; |
| 25 |
use MediaWiki\Utils\UrlUtils; |
| 26 |
use Psr\Log\LoggerAwareInterface; |
| 27 |
use Psr\Log\LoggerInterface; |
| 28 |
use Psr\Log\NullLogger; |
| 29 |
use Wikimedia\Http\TelemetryHeadersInterface; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
abstract class MWHttpRequest implements LoggerAwareInterface { |
| 39 |
public const SUPPORTS_FILE_POSTS = false; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
protected $timeout = 'default'; |
| 45 |
|
| 46 |
|
| 47 |
protected $content; |
| 48 |
|
| 49 |
protected $headersOnly = null; |
| 50 |
|
| 51 |
protected $postData = null; |
| 52 |
|
| 53 |
protected $proxy = null; |
| 54 |
|
| 55 |
protected $noProxy = false; |
| 56 |
|
| 57 |
protected $sslVerifyHost = true; |
| 58 |
|
| 59 |
protected $sslVerifyCert = true; |
| 60 |
|
| 61 |
protected $caInfo = null; |
| 62 |
|
| 63 |
protected $method = "GET"; |
| 64 |
|
| 65 |
protected $reqHeaders = []; |
| 66 |
|
| 67 |
protected $url; |
| 68 |
|
| 69 |
protected $parsedUrl; |
| 70 |
|
| 71 |
protected $callback; |
| 72 |
|
| 73 |
protected $maxRedirects = 5; |
| 74 |
|
| 75 |
protected $followRedirects = false; |
| 76 |
|
| 77 |
protected $connectTimeout; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
protected $cookieJar; |
| 83 |
|
| 84 |
|
| 85 |
protected $headerList = []; |
| 86 |
|
| 87 |
protected $respVersion = "0.9"; |
| 88 |
|
| 89 |
protected $respStatus = "200 Ok"; |
| 90 |
|
| 91 |
protected $respHeaders = []; |
| 92 |
|
| 93 |
|
| 94 |
protected $status; |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
protected $profiler; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
protected $profileName; |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
protected $logger; |
| 110 |
|
| 111 |
private UrlUtils $urlUtils; |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function __construct( |
| 123 |
$url, array $options, $caller = __METHOD__, ?Profiler $profiler = null |
| 124 |
) { |
| 125 |
$this->urlUtils = MediaWikiServices::getInstance()->getUrlUtils(); |
| 126 |
if ( !array_key_exists( 'timeout', $options ) |
| 127 |
|| !array_key_exists( 'connectTimeout', $options ) ) { |
| 128 |
throw new InvalidArgumentException( "timeout and connectionTimeout options are required" ); |
| 129 |
} |
| 130 |
$this->url = $this->urlUtils->expand( $url, PROTO_HTTP ) ?? false; |
| 131 |
$this->parsedUrl = $this->urlUtils->parse( (string)$this->url ) ?? false; |
| 132 |
|
| 133 |
$this->logger = $options['logger'] ?? new NullLogger(); |
| 134 |
$this->timeout = $options['timeout']; |
| 135 |
$this->connectTimeout = $options['connectTimeout']; |
| 136 |
|
| 137 |
if ( !$this->parsedUrl || !self::isValidURI( $this->url ) ) { |
| 138 |
$this->status = StatusValue::newFatal( 'http-invalid-url', $url ); |
| 139 |
} else { |
| 140 |
$this->status = StatusValue::newGood( 100 ); |
| 141 |
} |
| 142 |
|
| 143 |
if ( isset( $options['userAgent'] ) ) { |
| 144 |
$this->setUserAgent( $options['userAgent'] ); |
| 145 |
} |
| 146 |
if ( isset( $options['username'] ) && isset( $options['password'] ) ) { |
| 147 |
$this->setHeader( |
| 148 |
'Authorization', |
| 149 |
'Basic ' . base64_encode( $options['username'] . ':' . $options['password'] ) |
| 150 |
); |
| 151 |
} |
| 152 |
if ( isset( $options['originalRequest'] ) ) { |
| 153 |
$this->setOriginalRequest( $options['originalRequest'] ); |
| 154 |
} |
| 155 |
|
| 156 |
$members = [ "postData", "proxy", "noProxy", "sslVerifyHost", "caInfo", |
| 157 |
"method", "followRedirects", "maxRedirects", "sslVerifyCert", "callback" ]; |
| 158 |
|
| 159 |
foreach ( $members as $o ) { |
| 160 |
if ( isset( $options[$o] ) ) { |
| 161 |
|
| 162 |
|
| 163 |
if ( $o == 'method' ) { |
| 164 |
|
| 165 |
$options[$o] = strtoupper( $options[$o] ); |
| 166 |
} |
| 167 |
$this->$o = $options[$o]; |
| 168 |
} |
| 169 |
} |
| 170 |
|
| 171 |
if ( $this->noProxy ) { |
| 172 |
$this->proxy = ''; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
$this->profiler = $profiler; |
| 177 |
$this->profileName = $caller; |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
public function setLogger( LoggerInterface $logger ) { |
| 184 |
$this->logger = $logger; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
public static function canMakeRequests() { |
| 193 |
return function_exists( 'curl_init' ) || wfIniGetBool( 'allow_url_fopen' ); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
public function getContent() { |
| 202 |
return $this->content; |
| 203 |
} |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
public function setData( array $args ) { |
| 212 |
$this->postData = $args; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
public function addTelemetry( TelemetryHeadersInterface $telemetry ): void { |
| 222 |
foreach ( $telemetry->getRequestHeaders() as $header => $value ) { |
| 223 |
$this->setHeader( $header, $value ); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
protected function proxySetup() { |
| 233 |
$httpProxy = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 234 |
MainConfigNames::HTTPProxy ); |
| 235 |
$localHTTPProxy = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 236 |
MainConfigNames::LocalHTTPProxy ); |
| 237 |
|
| 238 |
if ( $this->noProxy ) { |
| 239 |
$this->proxy = ''; |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
if ( $this->proxy ) { |
| 245 |
return; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
if ( self::isLocalURL( $this->url ) ) { |
| 251 |
if ( $localHTTPProxy !== false ) { |
| 252 |
$this->setReverseProxy( $localHTTPProxy ); |
| 253 |
} |
| 254 |
} else { |
| 255 |
$this->proxy = (string)$httpProxy; |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
protected function setReverseProxy( string $proxy ) { |
| 270 |
$parsedProxy = $this->urlUtils->parse( $proxy ); |
| 271 |
if ( $parsedProxy === null ) { |
| 272 |
throw new InvalidArgumentException( "Invalid reverseProxy configured: $proxy" ); |
| 273 |
} |
| 274 |
|
| 275 |
$this->setHeader( 'Host', $this->parsedUrl['host'] ); |
| 276 |
|
| 277 |
$this->parsedUrl['scheme'] = $parsedProxy['scheme']; |
| 278 |
$this->parsedUrl['host'] = $parsedProxy['host']; |
| 279 |
if ( isset( $parsedProxy['port'] ) ) { |
| 280 |
$this->parsedUrl['port'] = $parsedProxy['port']; |
| 281 |
} else { |
| 282 |
unset( $this->parsedUrl['port'] ); |
| 283 |
} |
| 284 |
$this->url = UrlUtils::assemble( $this->parsedUrl ); |
| 285 |
|
| 286 |
$this->noProxy = true; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
private static function isLocalURL( $url ) { |
| 296 |
if ( MW_ENTRY_POINT === 'cli' ) { |
| 297 |
return false; |
| 298 |
} |
| 299 |
$localVirtualHosts = MediaWikiServices::getInstance()->getMainConfig()->get( |
| 300 |
MainConfigNames::LocalVirtualHosts ); |
| 301 |
|
| 302 |
|
| 303 |
$matches = []; |
| 304 |
if ( preg_match( '!^https?://([\w.-]+)[/:].*$!', $url, $matches ) ) { |
| 305 |
$host = $matches[1]; |
| 306 |
|
| 307 |
$domainParts = explode( '.', $host ); |
| 308 |
|
| 309 |
$domainParts = array_reverse( $domainParts ); |
| 310 |
|
| 311 |
$domain = ''; |
| 312 |
$countParts = count( $domainParts ); |
| 313 |
for ( $i = 0; $i < $countParts; $i++ ) { |
| 314 |
$domainPart = $domainParts[$i]; |
| 315 |
if ( $i == 0 ) { |
| 316 |
$domain = $domainPart; |
| 317 |
} else { |
| 318 |
$domain = $domainPart . '.' . $domain; |
| 319 |
} |
| 320 |
|
| 321 |
if ( in_array( $domain, $localVirtualHosts ) ) { |
| 322 |
return true; |
| 323 |
} |
| 324 |
} |
| 325 |
} |
| 326 |
|
| 327 |
return false; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
public function setUserAgent( $UA ) { |
| 334 |
$this->setHeader( 'User-Agent', $UA ); |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
public function setHeader( $name, $value ) { |
| 343 |
|
| 344 |
$this->reqHeaders[$name] = $value; |
| 345 |
} |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
protected function getHeaderList() { |
| 352 |
$list = []; |
| 353 |
|
| 354 |
if ( $this->cookieJar ) { |
| 355 |
$this->reqHeaders['Cookie'] = |
| 356 |
$this->cookieJar->serializeToHttpRequest( |
| 357 |
$this->parsedUrl['path'], |
| 358 |
$this->parsedUrl['host'] |
| 359 |
); |
| 360 |
} |
| 361 |
|
| 362 |
foreach ( $this->reqHeaders as $name => $value ) { |
| 363 |
$list[] = "$name: $value"; |
| 364 |
} |
| 365 |
|
| 366 |
return $list; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
public function setCallback( $callback ) { |
| 388 |
$this->doSetCallback( $callback ); |
| 389 |
} |
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
protected function doSetCallback( $callback ) { |
| 399 |
if ( $callback === null ) { |
| 400 |
$callback = [ $this, 'read' ]; |
| 401 |
} elseif ( !is_callable( $callback ) ) { |
| 402 |
$this->status->fatal( 'http-internal-error' ); |
| 403 |
throw new InvalidArgumentException( __METHOD__ . ': invalid callback' ); |
| 404 |
} |
| 405 |
$this->callback = $callback; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
public function read( $fh, $content ) { |
| 418 |
$this->content .= $content; |
| 419 |
return strlen( $content ); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
public function execute() { |
| 429 |
throw new LogicException( 'children must override this' ); |
| 430 |
} |
| 431 |
|
| 432 |
protected function prepare() { |
| 433 |
$this->content = ""; |
| 434 |
|
| 435 |
if ( strtoupper( $this->method ) == "HEAD" ) { |
| 436 |
$this->headersOnly = true; |
| 437 |
} |
| 438 |
|
| 439 |
$this->proxySetup(); |
| 440 |
|
| 441 |
if ( !$this->callback ) { |
| 442 |
$this->doSetCallback( null ); |
| 443 |
} |
| 444 |
|
| 445 |
if ( !isset( $this->reqHeaders['User-Agent'] ) ) { |
| 446 |
$http = MediaWikiServices::getInstance()->getHttpRequestFactory(); |
| 447 |
$this->setUserAgent( $http->getUserAgent() ); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
protected function parseHeader() { |
| 457 |
$lastname = ""; |
| 458 |
|
| 459 |
|
| 460 |
if ( !$this->status->isOK() ) { |
| 461 |
$this->respStatus = '0 Error'; |
| 462 |
} |
| 463 |
|
| 464 |
foreach ( $this->headerList as $header ) { |
| 465 |
if ( preg_match( "#^HTTP/([0-9.]+) (.*)#", $header, $match ) ) { |
| 466 |
$this->respVersion = $match[1]; |
| 467 |
$this->respStatus = $match[2]; |
| 468 |
} elseif ( preg_match( "#^[ \t]#", $header ) ) { |
| 469 |
$last = count( $this->respHeaders[$lastname] ) - 1; |
| 470 |
$this->respHeaders[$lastname][$last] .= "\r\n$header"; |
| 471 |
} elseif ( preg_match( "#^([^:]*):[\t ]*(.*)#", $header, $match ) ) { |
| 472 |
$this->respHeaders[strtolower( $match[1] )][] = $match[2]; |
| 473 |
$lastname = strtolower( $match[1] ); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
$this->parseCookies(); |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
protected function setStatus() { |
| 488 |
if ( !$this->respHeaders ) { |
| 489 |
$this->parseHeader(); |
| 490 |
} |
| 491 |
|
| 492 |
if ( (int)$this->respStatus > 0 && (int)$this->respStatus < 400 ) { |
| 493 |
$this->status->setResult( true, (int)$this->respStatus ); |
| 494 |
} else { |
| 495 |
[ $code, $message ] = explode( " ", $this->respStatus, 2 ); |
| 496 |
$this->status->setResult( false, (int)$this->respStatus ); |
| 497 |
$this->status->fatal( "http-bad-status", $code, $message ); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
public function getStatus() { |
| 509 |
if ( !$this->respHeaders ) { |
| 510 |
$this->parseHeader(); |
| 511 |
} |
| 512 |
|
| 513 |
return (int)$this->respStatus; |
| 514 |
} |
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
public function isRedirect() { |
| 522 |
if ( !$this->respHeaders ) { |
| 523 |
$this->parseHeader(); |
| 524 |
} |
| 525 |
|
| 526 |
$status = (int)$this->respStatus; |
| 527 |
|
| 528 |
if ( $status >= 300 && $status <= 303 ) { |
| 529 |
return true; |
| 530 |
} |
| 531 |
|
| 532 |
return false; |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
public function getResponseHeaders() { |
| 545 |
if ( !$this->respHeaders ) { |
| 546 |
$this->parseHeader(); |
| 547 |
} |
| 548 |
|
| 549 |
return $this->respHeaders; |
| 550 |
} |
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
public function getResponseHeader( $header ) { |
| 559 |
if ( !$this->respHeaders ) { |
| 560 |
$this->parseHeader(); |
| 561 |
} |
| 562 |
|
| 563 |
if ( isset( $this->respHeaders[strtolower( $header )] ) ) { |
| 564 |
$v = $this->respHeaders[strtolower( $header )]; |
| 565 |
return $v[count( $v ) - 1]; |
| 566 |
} |
| 567 |
|
| 568 |
return null; |
| 569 |
} |
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
public function setCookieJar( CookieJar $jar ) { |
| 579 |
$this->cookieJar = $jar; |
| 580 |
} |
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
public function getCookieJar() { |
| 588 |
if ( !$this->respHeaders ) { |
| 589 |
$this->parseHeader(); |
| 590 |
} |
| 591 |
|
| 592 |
return $this->cookieJar; |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
public function setCookie( $name, $value, array $attr = [] ) { |
| 605 |
if ( !$this->cookieJar ) { |
| 606 |
$this->cookieJar = new CookieJar; |
| 607 |
} |
| 608 |
|
| 609 |
if ( $this->parsedUrl && !isset( $attr['domain'] ) ) { |
| 610 |
$attr['domain'] = $this->parsedUrl['host']; |
| 611 |
} |
| 612 |
|
| 613 |
$this->cookieJar->setCookie( $name, $value, $attr ); |
| 614 |
} |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
protected function parseCookies() { |
| 620 |
if ( !$this->cookieJar ) { |
| 621 |
$this->cookieJar = new CookieJar; |
| 622 |
} |
| 623 |
|
| 624 |
if ( isset( $this->respHeaders['set-cookie'] ) ) { |
| 625 |
$url = parse_url( $this->getFinalUrl() ); |
| 626 |
if ( !isset( $url['host'] ) ) { |
| 627 |
$this->status->fatal( 'http-invalid-url', $url ); |
| 628 |
} else { |
| 629 |
foreach ( $this->respHeaders['set-cookie'] as $cookie ) { |
| 630 |
$this->cookieJar->parseCookieResponseHeader( $cookie, $url['host'] ); |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
public function getFinalUrl() { |
| 653 |
$headers = $this->getResponseHeaders(); |
| 654 |
|
| 655 |
|
| 656 |
if ( isset( $headers['location'] ) ) { |
| 657 |
$locations = $headers['location']; |
| 658 |
$domain = ''; |
| 659 |
$foundRelativeURI = false; |
| 660 |
$countLocations = count( $locations ); |
| 661 |
|
| 662 |
for ( $i = $countLocations - 1; $i >= 0; $i-- ) { |
| 663 |
$url = parse_url( $locations[$i] ); |
| 664 |
|
| 665 |
if ( isset( $url['scheme'] ) && isset( $url['host'] ) ) { |
| 666 |
$domain = $url['scheme'] . '://' . $url['host']; |
| 667 |
break; |
| 668 |
} else { |
| 669 |
$foundRelativeURI = true; |
| 670 |
} |
| 671 |
} |
| 672 |
|
| 673 |
if ( !$foundRelativeURI ) { |
| 674 |
return $locations[$countLocations - 1]; |
| 675 |
} |
| 676 |
if ( $domain ) { |
| 677 |
return $domain . $locations[$countLocations - 1]; |
| 678 |
} |
| 679 |
$url = parse_url( $this->url ); |
| 680 |
if ( isset( $url['scheme'] ) && isset( $url['host'] ) ) { |
| 681 |
return $url['scheme'] . '://' . $url['host'] . |
| 682 |
$locations[$countLocations - 1]; |
| 683 |
} |
| 684 |
} |
| 685 |
|
| 686 |
return $this->url; |
| 687 |
} |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
public function canFollowRedirects() { |
| 695 |
return true; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
public function setOriginalRequest( $originalRequest ) { |
| 711 |
if ( $originalRequest instanceof WebRequest ) { |
| 712 |
$originalRequest = [ |
| 713 |
'ip' => $originalRequest->getIP(), |
| 714 |
'userAgent' => $originalRequest->getHeader( 'User-Agent' ), |
| 715 |
]; |
| 716 |
} elseif ( |
| 717 |
!is_array( $originalRequest ) |
| 718 |
|| array_diff( [ 'ip', 'userAgent' ], array_keys( $originalRequest ) ) |
| 719 |
) { |
| 720 |
throw new InvalidArgumentException( __METHOD__ . ': $originalRequest must be a ' |
| 721 |
. "WebRequest or an array with 'ip' and 'userAgent' keys" ); |
| 722 |
} |
| 723 |
|
| 724 |
$this->reqHeaders['X-Forwarded-For'] = $originalRequest['ip']; |
| 725 |
$this->reqHeaders['X-Original-User-Agent'] = $originalRequest['userAgent']; |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
public static function isValidURI( $uri ) { |
| 745 |
return (bool)preg_match( |
| 746 |
'/^https?:\/\/[^\/\s]\S*$/D', |
| 747 |
$uri |
| 748 |
); |
| 749 |
} |
| 750 |
} |