ILIAS
release_5-4 Revision v5.4.26-12-gabc799a52e6
◀ ilDoc Overview
reverseproxy.php
Go to the documentation of this file.
1
<?
php
2
3
// The url we're proxying to.
4
$remoteUrl
=
'http://example.org/'
;
5
6
// The url we're proxying from. Please note that this must be a relative url,
7
// and basically acts as the base url.
8
//
9
// If your $remoteUrl doesn't end with a slash, this one probably shouldn't
10
// either.
11
$myBaseUrl
=
'/reverseproxy.php'
;
12
// $myBaseUrl = '/~evert/sabre/http/examples/reverseproxy.php/';
13
14
use
Sabre\HTTP\Client
;
15
use
Sabre\HTTP\Sapi
;
16
17
// Find the autoloader
18
$paths
= [
19
__DIR__ .
'/../vendor/autoload.php'
,
20
__DIR__ .
'/../../../autoload.php'
,
21
__DIR__ .
'/vendor/autoload.php'
,
22
23
];
24
25
foreach
(
$paths
as
$path
) {
26
if
(file_exists($path)) {
27
include
$path
;
28
break
;
29
}
30
}
31
32
33
$request
= Sapi::getRequest();
34
$request
->setBaseUrl(
$myBaseUrl
);
35
36
$subRequest
= clone
$request
;
37
38
// Removing the Host header.
39
$subRequest
->removeHeader(
'Host'
);
40
41
// Rewriting the url.
42
$subRequest
->setUrl(
$remoteUrl
. $request->getPath());
43
44
$client
=
new
Client
();
45
46
// Sends the HTTP request to the server
47
$response
=
$client
->send(
$subRequest
);
48
49
// Sends the response back to the client that connected to the proxy.
50
Sapi::sendResponse(
$response
);
$path
$path
Definition:
aliased.php:25
$remoteUrl
$remoteUrl
Definition:
reverseproxy.php:4
$client
$client
Definition:
reverseproxy.php:44
$subRequest
$subRequest
Definition:
reverseproxy.php:36
$paths
$paths
Definition:
reverseproxy.php:18
Client
This example demonstrates the ability for clients to work asynchronously.
$myBaseUrl
$myBaseUrl
Definition:
reverseproxy.php:11
php
$request
foreach($paths as $path) $request
Definition:
reverseproxy.php:33
Sapi
$response
$response
Definition:
reverseproxy.php:47
Sabre\HTTP\Client
A rudimentary HTTP client.
Definition:
Client.php:44
libs
composer
vendor
sabre
http
examples
reverseproxy.php
Generated on Thu Jan 16 2025 19:01:53 for ILIAS by
1.8.13 (using
Doxyfile
)