*/ public $query = array(); /** * Cookie names sent with the request. * * @var string[] */ public $cookies = array(); /** * The Accept header, lower case. * * @var string */ public $accept = ''; /** * The User-Agent header. * * @var string */ public $user_agent = ''; /** * Value of our own probe header, used by the environment check to see past our cache. * * @var string */ public $probe = ''; /** * Value of our own warming header: Gorilla Cache's own requests (warming, wp gorilla-cache explain) carry the * site's secret token, so only they leave a note of why a page was not stored. * * @var string */ public $warm = ''; /** * Builds a request from server variables and cookies. * * @param array $server Server variables ($_SERVER shape). * @param array $cookies Cookies ($_COOKIE shape); only the names are used. * @return GorillaCache_Engine_Request */ public static function from_arrays( array $server, array $cookies ) { $r = new self(); $r->method = isset( $server['REQUEST_METHOD'] ) ? strtoupper( (string) $server['REQUEST_METHOD'] ) : 'GET'; $https = isset( $server['HTTPS'] ) ? strtolower( (string) $server['HTTPS'] ) : ''; $port = isset( $server['SERVER_PORT'] ) ? (string) $server['SERVER_PORT'] : ''; if ( 'on' === $https || '1' === $https || '443' === $port ) { $r->scheme = 'https'; } $host = isset( $server['HTTP_HOST'] ) ? strtolower( trim( (string) $server['HTTP_HOST'] ) ) : ''; $host = rtrim( $host, '.' ); if ( 1 === preg_match( '/^[a-z0-9.-]{1,253}(:[0-9]{1,5})?$/', $host ) ) { // The default port is the same site: "example.com:443" over https is "example.com". $default = 'https' === $r->scheme ? ':443' : ':80'; $r->host = substr( $host, -strlen( $default ) ) === $default ? substr( $host, 0, -strlen( $default ) ) : $host; } $uri = isset( $server['REQUEST_URI'] ) ? (string) $server['REQUEST_URI'] : '/'; $parts = explode( '?', $uri, 2 ); $r->path = '' !== $parts[0] ? $parts[0] : '/'; $r->query = isset( $parts[1] ) ? self::parse_query( $parts[1] ) : array(); $r->accept = isset( $server['HTTP_ACCEPT'] ) ? strtolower( (string) $server['HTTP_ACCEPT'] ) : ''; $r->user_agent = isset( $server['HTTP_USER_AGENT'] ) ? (string) $server['HTTP_USER_AGENT'] : ''; $r->probe = isset( $server['HTTP_X_GORILLA_CACHE_PROBE'] ) ? (string) $server['HTTP_X_GORILLA_CACHE_PROBE'] : ''; $r->warm = isset( $server['HTTP_X_GORILLA_CACHE_WARM'] ) ? (string) $server['HTTP_X_GORILLA_CACHE_WARM'] : ''; $r->cookies = array_map( 'strval', array_keys( $cookies ) ); return $r; } /** * Splits a raw query string into its pairs without PHP's renaming of dots and spaces. * * @param string $raw Raw query string (after "?"). * @return array */ public static function parse_query( $raw ) { $pairs = array(); foreach ( explode( '&', (string) $raw ) as $pair ) { if ( '' === $pair ) { continue; } $name = explode( '=', $pair, 2 )[0]; $pairs[] = array( strtolower( rawurldecode( str_replace( '+', ' ', $name ) ) ), $pair ); } return $pairs; } }