summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2013-07-23 08:35:36 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2013-07-23 08:35:36 (GMT)
commitcf1b251ed75ce07d381bb4bb480496652d6e2692 (patch)
treeff6a3fdc9f2fd8a58032ce5929c4c9a6b82c1fed
parent9534fa2b9f0d63a7979b7fccf7514832ed9c36d5 (diff)
downloadiRony-cf1b251ed75ce07d381bb4bb480496652d6e2692.tar.gz
Adjust URIs in request body when forwarding
-rw-r--r--public_html/debug.php9
1 files changed, 6 insertions, 3 deletions
diff --git a/public_html/debug.php b/public_html/debug.php
index 4f15c7e..af03921 100644
--- a/public_html/debug.php
+++ b/public_html/debug.php
@@ -44,7 +44,7 @@ $http_headers = array();
foreach (apache_request_headers() as $hdr => $value) {
if ($hdr == 'Destination')
$value = str_replace($base_uri, $base_uri . 'index.php/', $value);
- $http_headers[] = "$hdr: $value";
+ $http_headers[$hdr] = "$hdr: $value";
}
// read HTTP request body
$in = fopen('php://input', 'r');
@@ -54,6 +54,9 @@ fclose($in);
$rcube->write_log('davdebug', $_SERVER['REQUEST_METHOD'] . ' ' . $_SERVER['REQUEST_URI'] . ' ' . $_SERVER['SERVER_PROTOCOL'] . "\n" .
join("\n", $http_headers) . "\n\n" . $http_body);
+// fix URIs in request body
+$http_body = preg_replace("!(<d:href>$base_uri)!i", '\\1index.php/', $http_body);
+$http_headers['Content-Length'] = "Content-Length: " . strlen($http_body);
// forward the full request to index.php
$rel_url = substr($_SERVER['REQUEST_URI'], strlen($base_uri));
@@ -62,7 +65,7 @@ $port = 80;
$path = $base_uri . 'index.php/' . $rel_url;
// remove Host: header
-array_shift($http_headers);
+unset($http_headers['Host']);
$response_headers = array();
// re-send using curl
@@ -71,7 +74,7 @@ curl_setopt($ch, CURLOPT_URL, "http://$host:$port$path");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
curl_setopt($ch, CURLOPT_POSTFIELDS, $http_body);
-curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
+curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($http_headers));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) use (&$response_headers){
list($key, $val) = explode(": ", rtrim($header), 2);