private function checkRequestHeader(Gpf_Net_Server_Http_Request $request) { //HTTP/1.1 All Internet-based HTTP/1.1 servers MUST respond with a 400 // (Bad Request) status code to any HTTP/1.1 request message which // lacks a Host header field. if ($request->getVersion() == '1.1' && !$request->existsHeader('Host')) { $response = Gpf_Net_Server_Http_Response::createBadRequest("Host header is missing"); throw new Gpf_Net_Server_Http_RequestException($response); } // if($request->existsHeader('TE')) { // $response = Gpf_Net_Server_Http_Response::createUnimplemented( // "Transfer-Encoding not supported"); // throw new Gpf_Net_Server_Http_RequestException($response); // } if ($request->headerContain('Content-Type', 'multipart/byteranges')) { $response = Gpf_Net_Server_Http_Response::createUnimplemented("Content-Type multipart/byteranges not supported"); throw new Gpf_Net_Server_Http_RequestException($response); } }
/** * @return Gpf_Net_Server_Http_Request */ public static function parseHeader($requestString) { $lines = explode("\n", $requestString); $firstLine = 0; //HTTP1.1 servers SHOULD ignore any empty line(s) received where a Request-Line is expected while ($firstLine < count($lines) && strlen($lines[$firstLine++]) == 0) { } $regs = array(); if (!preg_match("'^([^ ]+)[ ]+([^ ]+)[ ]+HTTP/([^ ]+)\$'", $lines[--$firstLine], $regs)) { $response = Gpf_Net_Server_Http_Response::createBadRequest("Bad request"); throw new Gpf_Net_Server_Http_RequestException($response); } $request = new Gpf_Net_Server_Http_Request($regs[1], $regs[2], $regs[3]); for ($i = $firstLine + 1; $i < count($lines); $i++) { $line = rtrim($lines[$i]); //HTTP1.1 Header fields can be extended over multiple lines by preceding // each extra line with at least one SP or HT while ($i < count($lines) - 1 && $lines[$i + 1] != ltrim($lines[$i + 1])) { $line .= ' ' . trim($lines[$i + 1]); $i++; } $regs = array(); if (!preg_match("'^([^: ]+): (.+)\$'", $line, $regs)) { $response = Gpf_Net_Server_Http_Response::createBadRequest("Request header filed is missing : separator"); throw new Gpf_Net_Server_Http_RequestException($response); } $request->addHeader($regs[1], $regs[2]); } $request->exportPhpVars(); return $request; }