示例#1
0
文件: Jar.php 项目: Garth619/Femi9
 /**
  * Parse all cookies from a response and attach them to the response
  *
  * @var Requests_Response $response
  */
 public function before_redirect_check(Requests_Response &$return)
 {
     $url = $return->url;
     if (!$url instanceof Requests_IRI) {
         $url = new Requests_IRI($url);
     }
     $cookies = Requests_Cookie::parse_from_headers($return->headers, $url);
     $this->cookies = array_merge($this->cookies, $cookies);
     $return->cookies = $this;
 }
示例#2
0
 /**
  * Manually set cookies without a domain/path set should always be valid
  *
  * Cookies parsed from headers internally in Requests will always have a
  * domain/path set, but those created manually will not. Manual cookies
  * should be regarded as "global" cookies (that is, set for `.`)
  */
 public function testUrlMatchManuallySet()
 {
     $cookie = new Requests_Cookie('requests-testcookie', 'testvalue');
     $this->assertTrue($cookie->domainMatches('example.com'));
     $this->assertTrue($cookie->domainMatches('example.net'));
     $this->assertTrue($cookie->pathMatches('/'));
     $this->assertTrue($cookie->pathMatches('/test'));
     $this->assertTrue($cookie->pathMatches('/test/'));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.com/')));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.com/test')));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.com/test/')));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.net/')));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.net/test')));
     $this->assertTrue($cookie->uriMatches(new Requests_IRI('http://example.net/test/')));
 }
示例#3
0
 /**
  * Parse all cookies from a response and attach them to the response
  *
  * @var Requests_Response $response
  */
 public function before_redirect_check(Requests_Response &$return)
 {
     $cookies = Requests_Cookie::parseFromHeaders($return->headers);
     $this->cookies = array_merge($this->cookies, $cookies);
     $return->cookies = $this;
 }
示例#4
0
<?php

// First, include Requests
include '../library/Requests.php';
// Next, make sure Requests can load internal classes
Requests::register_autoloader();
// Say you need to fake a login cookie
$c = new Requests_Cookie('login_uid', 'something');
// Now let's make a request!
$request = Requests::get('http://httpbin.org/cookies', array('Cookie' => $c->formatForHeader()));
// Check what we received
var_dump($request);
示例#5
0
 /**
  * @dataProvider parseFromHeadersProvider
  */
 public function testParsingHeaderWithOrigin($header, $origin, $expected, $expected_attributes = array(), $expected_flags = array())
 {
     $origin = new Requests_IRI($origin);
     $headers = new Requests_Response_Headers();
     $headers['Set-Cookie'] = $header;
     // Set the reference time to 2014-01-01 00:00:00
     $reference_time = gmmktime(0, 0, 0, 1, 1, 2014);
     $parsed = Requests_Cookie::parse_from_headers($headers, $origin, $reference_time);
     if (isset($expected['invalid'])) {
         $this->assertCount(0, $parsed);
         return;
     }
     $this->assertCount(1, $parsed);
     $cookie = reset($parsed);
     $this->check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags);
 }
示例#6
0
 public function testEmptyAttributes()
 {
     $cookie = Requests_Cookie::parse('foo=bar; HttpOnly');
     $this->assertTrue($cookie->attributes['httponly']);
 }