/** * @test */ public function shouldReturnIpFromREMOTE_ADDR() { //given $_SERVER['REMOTE_ADDR'] = '10.170.12.53'; //when $ip = RequestHeaders::ip(); //then $this->assertEquals('10.170.12.53', $ip); }
public static function resolve() { $accept = array_keys(RequestHeaders::accept()) ?: array('*/*'); $supported = array('application/json' => 'application/json', 'application/xml' => 'application/xml', 'application/*' => 'application/json', 'text/html' => 'text/html', 'text/*' => 'text/html'); $intersection = array_intersect($accept, array_keys($supported)); if ($intersection) { return $supported[Arrays::first($intersection)]; } return Arrays::getValue($supported, ContentType::value(), 'text/html'); }
public static function validate() { $csrfToken = self::getCsrfToken(); if (!isset($_COOKIE['csrftoken']) || $_COOKIE['csrftoken'] != $csrfToken) { self::_throwException(); } $headerToken = Arrays::getValue(RequestHeaders::all(), 'X-Csrftoken'); $postToken = Arrays::getValue($_POST, 'csrftoken'); if ($headerToken != $csrfToken && $postToken != $csrfToken) { self::_throwException(); } }