Skip to content
Snippets Groups Projects
  • David Fifield's avatar
    41ccd908
    Use HTTPS for example forwarding URLs. · 41ccd908
    David Fifield authored
    All our deployed backends are using HTTPS in forwarding. Might as well
    make it the default for DIY deployers. I seem to remember that we once
    had trouble on some platform (maybe some PHP host) because the installed
    PHP library didn't have SSL support, but whatever.
    41ccd908
    History
    Use HTTPS for example forwarding URLs.
    David Fifield authored
    All our deployed backends are using HTTPS in forwarding. Might as well
    make it the default for DIY deployers. I seem to remember that we once
    had trouble on some platform (maybe some PHP host) because the installed
    PHP library didn't have SSL support, but whatever.
index.php 783 B
<?php
	// A PHP reflector for meek.

	$forwardURL = "https://meek.bamsoftware.com/";

	$headerArray = array();
	if (array_key_exists("HTTP_X_SESSION_ID", $_SERVER)) {
		$headerArray[] = "X-Session-Id: " . $_SERVER["HTTP_X_SESSION_ID"];
	}

	function HeaderFunc($ch, $header) {
		if (explode( ":", $header)[0] == "Content-Type") {
			header($header);
		}
		return strlen($header);
	}

	$curlOpt = array(
		CURLOPT_HTTPHEADER => $headerArray,
		CURLOPT_CUSTOMREQUEST => $_SERVER["REQUEST_METHOD"],
		CURLOPT_POSTFIELDS => file_get_contents("php://input"),
		CURLOPT_HEADERFUNCTION => "HeaderFunc",
	);

	$ch = curl_init($forwardURL);
	curl_setopt_array($ch, $curlOpt);

	if (!curl_exec($ch)) {
		header("HTTP/1.1 502 Bad Gateway");
		echo "502 Bad Gateway\n";
	}

	curl_close($ch);
?>