예제 #1
0
 /**
  * @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);
 }
예제 #2
0
 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');
 }
예제 #3
0
 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();
     }
 }