Skip to content

Commit

Permalink
ws
Browse files Browse the repository at this point in the history
  • Loading branch information
razzed committed Apr 6, 2020
1 parent 20f0110 commit 9835f7d
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions classes/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class Request extends Hookable {
protected $url_parts = array(
'host' => null,
'scheme' => null,
'path' => null
'path' => null,
);

/**
Expand Down Expand Up @@ -179,7 +179,7 @@ public function __construct(Application $application, $settings = null) {
$this->init = "not-inited";
} else {
throw new Exception_Parameter("{method} Requires array, Request, or null", array(
"method" => __METHOD__
"method" => __METHOD__,
));
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public function initialize_from_globals() {

$this->call_hook(array(
"initialize",
"initialize_from_globals"
"initialize_from_globals",
));

return $this;
Expand Down Expand Up @@ -249,7 +249,7 @@ public function initialize_from_request(Request $request) {

$this->call_hook(array(
"initialize",
"initialize_from_request"
"initialize_from_request",
));

return $this;
Expand All @@ -266,7 +266,7 @@ public function initialize_from_request(Request $request) {
public function initialize_from_settings($settings) {
if (is_string($settings)) {
$settings = array(
"url" => $settings
"url" => $settings,
);
} elseif ($settings instanceof Request) {
$this->_copy_from($settings);
Expand All @@ -275,7 +275,7 @@ public function initialize_from_settings($settings) {
if (!is_array($settings)) {
throw new Exception_Parameter("Request constructor should take a string, array or Request {type} passed in settings {settings}", array(
"type" => type($settings),
"settings" => $settings
"settings" => $settings,
));
}
$method = $uri = $url = $data = $data_file = $data_raw = $ip = $remote_ip = $server_ip = null;
Expand All @@ -299,7 +299,7 @@ public function initialize_from_settings($settings) {
if ($data_file) {
if (!is_file($data_file)) {
throw new Exception_File_NotFound($data_file, "Passed {filename} as settings to new Request {settings}", array(
"settings" => $settings
"settings" => $settings,
));
}
$this->data_file = $data_file;
Expand All @@ -318,7 +318,7 @@ public function initialize_from_settings($settings) {
$this->init = "settings";
$this->call_hook(array(
"initialize",
"initialize_from_settings"
"initialize_from_settings",
));

return $this;
Expand Down Expand Up @@ -360,16 +360,16 @@ public function parse_accept() {
return array(
"*/*" => array(
"q" => 1,
"pattern" => "#[^/]+/[^/]+#"
)
"pattern" => "#[^/]+/[^/]+#",
),
);
}
$items = explode(",", preg_replace('/\s+/', '', $accept));
foreach ($items as $item_index => $item) {
$item_parts = explode(";", $item);
$type = $subtype = "*";
$attr = array(
"weight" => 1
"weight" => 1,
);

foreach ($item_parts as $item_part) {
Expand Down Expand Up @@ -401,7 +401,7 @@ public function parse_accept() {
$key = "$type/$subtype";
$attr['pattern'] = '#' . strtr($key, array(
"*" => "[^/]+",
"+" => "\\+"
"+" => "\\+",
)) . '#';
$result[$key] = $attr;
}
Expand Down Expand Up @@ -467,7 +467,7 @@ public function data() {
case "multipart/form-data":
$this->data = $_REQUEST;
break;
default :
default:
$this->data = array();
break;
}
Expand Down Expand Up @@ -627,7 +627,7 @@ public function get_not_empty($name = null, $default = null) {
if ($name === null) {
return ArrayTools::clean($this->variables, array(
"",
null
null,
));
}
return aevalue($this->variables, $name, $default);
Expand Down Expand Up @@ -985,7 +985,7 @@ protected function _calculate_byte_range($size) {

return array(
$start,
$end
$end,
);
}

Expand Down Expand Up @@ -1071,7 +1071,7 @@ public function __toString() {
"headers" => $this->headers,
"files" => $this->files,
"cookies" => $this->cookies,
"variables" => $this->variables
"variables" => $this->variables,
));
}

Expand All @@ -1094,7 +1094,7 @@ public static function max_upload_size($all = false) {
}
}
return $result + array(
"limiting_factor" => $mink
"limiting_factor" => $mink,
);
}
return min($upload_max_filesize, $post_max_size, $memory_limit);
Expand Down Expand Up @@ -1122,7 +1122,7 @@ private function set_method($method) {
if (!array_key_exists($method, Net_HTTP::$methods)) {
throw new Exception_Parameter("Unknown method in {method_name}({method}", array(
"method_name" => __METHOD__,
"method" => $method
"method" => $method,
));
}
$this->method = $method;
Expand All @@ -1145,7 +1145,7 @@ private function _valid_url_parts() {
'scheme' => 'http',
'host' => 'localhost',
'port' => 80,
'path' => ''
'path' => '',
);
}

Expand Down Expand Up @@ -1188,7 +1188,7 @@ private static function http_headers_from_server(array $server) {
foreach ($server as $key => $value) {
foreach (array(
"http-" => true,
"content-" => false
"content-" => false,
) as $prefix => $unprefix) {
$len = strlen($prefix);
if (substr($key, 0, $len) === $prefix) {
Expand All @@ -1198,16 +1198,19 @@ private static function http_headers_from_server(array $server) {
}
return $headers;
}

private function _derive_uri() {
return $this->query() ? URL::query_format($this->path() . $this->query()) : $this->path();
}

private function url_from_server($server) {
$parts['scheme'] = $this->current_scheme($server);
$parts['host'] = $this->current_host();
$parts['port'] = $this->current_port($server);
$parts['path'] = $this->current_uri($server);
return URL::unparse($parts);
}

private function current_scheme(array $server) {
// Amazon load balancers
$proto = $this->header("X-Forwarded-Proto");
Expand All @@ -1216,10 +1219,12 @@ private function current_scheme(array $server) {
}
return avalue($server, 'HTTPS') === "on" ? "https" : "http";
}

private function current_host() {
$host = $this->header("Host");
return strtolower(StringTools::left($host, ":", $host));
}

private function current_port(array $server) {
// Amazon load balancers
$port = $this->header("X-Forwarded-Port");
Expand All @@ -1228,6 +1233,7 @@ private function current_port(array $server) {
}
return avalue($server, "SERVER_PORT", 80);
}

private function current_uri(array $server) {
return avalue($server, 'REQUEST_URI');
}
Expand All @@ -1243,7 +1249,7 @@ public function prefer_json() {
}
return $this->accept_priority(array(
"application/json",
"text/html"
"text/html",
)) === "application/json";
}

Expand All @@ -1259,7 +1265,7 @@ private static function _find_remote_key(array $server, $default = null) {
$ks = array(
"HTTP_CLIENT_IP",
"HTTP_X_FORWARDED_FOR",
"REMOTE_ADDR"
"REMOTE_ADDR",
);
foreach ($ks as $k) {
if (!isset($server[$k])) {
Expand Down

0 comments on commit 9835f7d

Please sign in to comment.