/** * Request object provided to the Photon views. * * @param &$mess Mongrel2 request message object. */ function __construct(&$mess) { $this->mess = $mess; $this->path = $this->mess->path; $this->method = $this->mess->headers->METHOD; $this->sender = $this->mess->sender; $this->client = $this->mess->conn_id; $this->headers = $this->mess->headers; if (isset($this->mess->headers->QUERY)) { \mb_parse_str($this->mess->headers->QUERY, $this->GET); $this->query = $this->mess->headers->QUERY; } if ('POST' === $this->mess->headers->METHOD || 'PUT' === $this->mess->headers->METHOD) { if (isset($this->mess->headers->{'content-type'}) === false) { $this->BODY =& $mess->body; } else { if (0 === strpos($this->mess->headers->{'content-type'}, 'multipart/form-data; boundary=')) { $parser = new \photon\http\multipartparser\MultiPartParser($mess->headers, $mess->body); foreach ($parser->parse() as $part) { if ('FIELD' === $part['of_type']) { add_to_post($this->POST, $part['name'], $part['data']); } else { add_file_to_post($this->FILES, $part['name'], $part); } } } else { if (false !== mb_strstr($this->mess->headers->{'content-type'}, 'application/x-www-form-urlencoded')) { $this->POST = parse_str(substr(stream_get_contents($mess->body), 0, -1)); } else { $this->BODY =& $mess->body; } } } } else { if ('JSON' === $this->mess->headers->METHOD) { $this->BODY = $this->mess->body; } } $this->COOKIE = CookieHandler::parse($this->mess->headers, Conf::f('secret_key', '')); }
public function testParseSimpleCookie() { $headers = (object) array('cookie' => 'foo=czozOiJiYXIiOw.6o_2mL7ZL4HgcezUZT4Nn9VcIuM; bar=czozOiJmb28iOw.pa7EFOZK0OkBpqpaS_P2Qo1Zccw;'); $cookies = CookieHandler::parse($headers, 'my-key'); $this->assertEquals('bar', $cookies['foo']); }