Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Commit

Permalink
Fixes and tweaks related to HTTP ports.
Browse files Browse the repository at this point in the history
* Omit the standard HTTP port 80 from PROXY_PREFIX if the proxy is being accessed via that port.
* Properly handle nonstandard HTTP ports inside proxied pages.
  • Loading branch information
joshdick committed Jan 21, 2014
1 parent 31a76f8 commit adf9810
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions miniProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function getallheaders() {
}
}

define("PROXY_PREFIX", "http" . (isset($_SERVER['HTTPS']) ? "s" : "") . "://" . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["SCRIPT_NAME"] . "/");
define("PROXY_PREFIX", "http" . (isset($_SERVER['HTTPS']) ? "s" : "") . "://" . $_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "") . $_SERVER["SCRIPT_NAME"] . "/");

//Makes an HTTP request via cURL, using request data that was passed directly to this script.
function makeRequest($url) {
Expand Down Expand Up @@ -119,7 +119,8 @@ function rel2abs($rel, $base) {
extract(parse_url($base)); //Parse base URL and convert to local variables: $scheme, $host, $path
$path = isset($path) ? preg_replace('#/[^/]*$#', "", $path) : "/"; //Remove non-directory element from path
if ($rel[0] == '/') $path = ""; //Destroy path if relative url points to root
$abs = "$host$path/$rel"; //Dirty absolute URL
$port = isset($port) && $port != 80 ? ":" . $port : "";
$abs = "$host$path$port/$rel"; //Dirty absolute URL
for ($n = 1; $n > 0; $abs = preg_replace(array("#(/\.?/)#", "#/(?!\.\.)[^/]+/\.\./#"), "/", $abs, -1, $n)) {} //Replace '//' or '/./' or '/foo/../' with '/'
return $scheme . "://" . $abs; //Absolute URL is ready.
}
Expand Down

0 comments on commit adf9810

Please sign in to comment.