function testMethodStuff() { $q = new folksoQuery(array('REQUEST_METHOD' => 'GET'), array('folksores' => 1234), array()); $this->assertIsA($q, folksoQuery, 'Problem with object creation'); $this->assertEqual($q->method(), 'get', 'Reporting incorrect method'); $this->assertFalse($q->is_write_method, 'is_write_method should report false on GET'); $qq = new folksoQuery(array('REQUEST_METHOD' => 'POST'), array('folksostuff' => 'hoohoa'), array()); $this->assertEqual($qq->method(), 'post', 'Reporting incorrect method, should be post'); $this->assertTrue($qq->is_write_method(), 'Is write method should say true on POST'); }
/** * Based on the request received, checks each response object is * checked to see if it is equiped to handle the request. */ public function Respond() { if (!$this->valid_method()) { // some kind of error header('HTTP/1.0 405'); print "NOT OK. Illegal request method for this resource."; return; } if (!$this->validClientAddress($_SERVER['REMOTE_HOST'], $_SERVER['REMOTE_ADDR'])) { header('HTTP/1.0 403'); print "Sorry, this not available to you"; return; } $q = new folksoQuery($_SERVER, $_GET, $_POST); $realm = 'folkso'; $loc = new folksoFabula(); $dbc = $loc->locDBC(); $fks = new folksoSession($dbc); /** * $sid: session ID */ $sid = $_COOKIE['folksosess'] ? $_COOKIE['folksosess'] : $q->get_param('session'); try { $fks->setSid($sid); } catch (badSidException $e) { if ($q->is_write_method()) { header('HTTP/1.1 403 Login required'); // redirect instead header('Location: ' . $loc->loginPage()); exit; } } /* check each response object and run the response if activatep returns true*/ $repflag = false; if (count($this->responseObjects) === 0) { trigger_error("No responseObjects available", E_USER_ERROR); } /** Walking the response objects **/ foreach ($this->responseObjects as $resp) { if ($resp->activatep($q)) { $repflag = true; $resp->Respond($q, $dbc, $fks); break; } } /** check for no valid response **/ if (!$repflag) { header('HTTP/1.1 400'); print "Client did not make a valid query. (folksoServer)"; // default response or error page... } }