forked from postmanlabs/postman-app-support
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed the history section links.
- Loading branch information
unknown
authored and
unknown
committed
Jul 12, 2011
1 parent
e5509f3
commit 56dcc52
Showing
4 changed files
with
176 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
/** | ||
* Access the HTTP Request | ||
*/ | ||
class http_request { | ||
|
||
/** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */ | ||
var $add_headers = array('CONTENT_TYPE', 'CONTENT_LENGTH'); | ||
|
||
/** | ||
* Construtor | ||
* Retrieve HTTP Body | ||
* @param Array Additional Headers to retrieve | ||
*/ | ||
function http_request($add_headers = false) { | ||
|
||
$this->retrieve_headers($add_headers); | ||
$this->body = @file_get_contents('php://input'); | ||
} | ||
|
||
/** | ||
* Retrieve the HTTP request headers from the $_SERVER superglobal | ||
* @param Array Additional Headers to retrieve | ||
*/ | ||
function retrieve_headers($add_headers = false) { | ||
|
||
if ($add_headers) { | ||
$this->add_headers = array_merge($this->add_headers, $add_headers); | ||
} | ||
|
||
if (isset($_SERVER['HTTP_METHOD'])) { | ||
$this->method = $_SERVER['HTTP_METHOD']; | ||
unset($_SERVER['HTTP_METHOD']); | ||
} else { | ||
$this->method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false; | ||
} | ||
$this->protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : false; | ||
$this->request_method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : false; | ||
|
||
$this->headers = array(); | ||
foreach($_SERVER as $i=>$val) { | ||
if (strpos($i, 'HTTP_') === 0 || in_array($i, $this->add_headers)) { | ||
$name = str_replace(array('HTTP_', '_'), array('', '-'), $i); | ||
$this->headers[$name] = $val; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve HTTP Method | ||
*/ | ||
function method() { | ||
return $this->method; | ||
} | ||
|
||
/** | ||
* Retrieve HTTP Body | ||
*/ | ||
function body() { | ||
return $this->body; | ||
} | ||
|
||
/** | ||
* Retrieve an HTTP Header | ||
* @param string Case-Insensitive HTTP Header Name (eg: "User-Agent") | ||
*/ | ||
function header($name) { | ||
$name = strtoupper($name); | ||
return isset($this->headers[$name]) ? $this->headers[$name] : false; | ||
} | ||
|
||
/** | ||
* Retrieve all HTTP Headers | ||
* @return array HTTP Headers | ||
*/ | ||
function headers() { | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* Return Raw HTTP Request (note: This is incomplete) | ||
* @param bool ReBuild the Raw HTTP Request | ||
*/ | ||
function raw($refresh = false) { | ||
|
||
if (isset($this->raw) && !$refresh) { | ||
return $this->raw; // return cached | ||
} | ||
|
||
$headers = $this->headers(); | ||
$this->raw = "{$this->method}\r\n"; | ||
|
||
foreach($headers as $i=>$header) { | ||
$this->raw .= "$i: $header\r\n"; | ||
} | ||
|
||
$this->raw .= "\r\n{$this->body}"; | ||
|
||
return $this->raw; | ||
} | ||
} | ||
|
||
/** | ||
* | ||
* Echos the HTTP Request back the client/browser (in the HTTP Body) | ||
*/ | ||
$http_request = new http_request(); | ||
$resp = $http_request->raw(); | ||
echo $resp; |