Update composer dependencies

This commit is contained in:
Kijin Sung 2017-06-29 23:39:23 +09:00
parent 49cc39e507
commit cbd324c35b
428 changed files with 17862 additions and 5885 deletions

6
vendor/rmccue/requests/tests/Auth/Basic.php vendored Executable file → Normal file
View file

@ -22,7 +22,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
'auth' => array('user', 'passwd'),
'transport' => $transport,
);
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body);
@ -43,7 +43,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
'auth' => new Requests_Auth_Basic(array('user', 'passwd')),
'transport' => $transport,
);
$request = Requests::get('http://httpbin.org/basic-auth/user/passwd', array(), $options);
$request = Requests::get(httpbin('/basic-auth/user/passwd'), array(), $options);
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body);
@ -65,7 +65,7 @@ class RequestsTest_Auth_Basic extends PHPUnit_Framework_TestCase {
'transport' => $transport,
);
$data = 'test';
$request = Requests::post('http://httpbin.org/post', array(), $data, $options);
$request = Requests::post(httpbin('/post'), array(), $data, $options);
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body);

29
vendor/rmccue/requests/tests/ChunkedEncoding.php vendored Executable file → Normal file
View file

@ -15,6 +15,18 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
"02\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
"abra\ncadabra\nall we got\n"
),
array(
"02;foo=bar;hello=world\r\nab\r\n04;foo=baz\r\nra\nc\r\n06;justfoo\r\nadabra\r\n0c\r\n\nall we got\n",
"abra\ncadabra\nall we got\n"
),
array(
"02;foo=\"quoted value\"\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
"abra\ncadabra\nall we got\n"
),
array(
"02;foo-bar=baz\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n",
"abra\ncadabra\nall we got\n"
),
);
}
@ -34,12 +46,24 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
$this->assertEquals($expected, $response->body);
}
public static function notChunkedProvider() {
return array(
'invalid chunk size' => array( 'Hello! This is a non-chunked response!' ),
'invalid chunk extension' => array( '1BNot chunked\r\nLooks chunked but it is not\r\n' ),
'unquoted chunk-ext-val with space' => array( "02;foo=unquoted with space\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
'unquoted chunk-ext-val with forbidden character' => array( "02;foo={unquoted}\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
'invalid chunk-ext-name' => array( "02;{foo}=bar\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
'incomplete quote for chunk-ext-value' => array( "02;foo=\"no end quote\r\nab\r\n04\r\nra\nc\r\n06\r\nadabra\r\n0c\r\n\nall we got\n" ),
);
}
/**
* Response says it's chunked, but actually isn't
* @dataProvider notChunkedProvider
*/
public function testNotActuallyChunked() {
public function testNotActuallyChunked($body) {
$transport = new MockTransport();
$transport->body = 'Hello! This is a non-chunked response!';
$transport->body = $body;
$transport->chunked = true;
$options = array(
@ -50,6 +74,7 @@ class RequestsTest_ChunkedDecoding extends PHPUnit_Framework_TestCase {
$this->assertEquals($transport->body, $response->body);
}
/**
* Response says it's chunked and starts looking like it is, but turns out
* that they're lying to us

482
vendor/rmccue/requests/tests/Cookies.php vendored Executable file → Normal file
View file

@ -8,8 +8,8 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$this->assertEquals('testvalue', $cookie->value);
$this->assertEquals('testvalue', (string) $cookie);
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForHeader());
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForSetCookie());
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_set_cookie());
}
public function testCookieWithAttributes() {
@ -19,8 +19,8 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals('requests-testcookie=testvalue', $cookie->formatForHeader());
$this->assertEquals('requests-testcookie=testvalue; httponly; path=/', $cookie->formatForSetCookie());
$this->assertEquals('requests-testcookie=testvalue', $cookie->format_for_header());
$this->assertEquals('requests-testcookie=testvalue; httponly; path=/', $cookie->format_for_set_cookie());
}
public function testEmptyCookieName() {
@ -79,7 +79,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$options = array(
'follow_redirects' => false,
);
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
$url = httpbin('/cookies/set?requests-testcookie=testvalue');
$response = Requests::get($url, array(), $options);
@ -92,7 +92,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$options = array(
'follow_redirects' => true,
);
$url = 'http://httpbin.org/cookies/set?requests-testcookie=testvalue';
$url = httpbin('/cookies/set?requests-testcookie=testvalue');
$response = Requests::get($url, array(), $options);
@ -105,7 +105,7 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$options = array(
'cookies' => $cookies,
);
$response = Requests::get('http://httpbin.org/cookies/set', array(), $options);
$response = Requests::get(httpbin('/cookies/set'), array(), $options);
$data = json_decode($response->body, true);
$this->assertInternalType('array', $data);
@ -124,6 +124,23 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$this->assertEquals('testvalue1', $data['requests-testcookie1']);
}
/**
* @depends testSendingCookie
*/
public function testCookieExpiration() {
$options = array(
'follow_redirects' => true,
);
$url = httpbin('/cookies/set/testcookie/testvalue');
$url .= '?expiry=1';
$response = Requests::get($url, array(), $options);
$response->throw_for_status();
$data = json_decode($response->body, true);
$this->assertEmpty($data['cookies']);
}
public function testSendingCookieWithJar() {
$cookies = new Requests_Cookie_Jar(array(
'requests-testcookie1' => 'testvalue1',
@ -171,4 +188,455 @@ class RequestsTest_Cookies extends PHPUnit_Framework_TestCase {
$this->assertArrayHasKey('requests-testcookie', $data);
$this->assertEquals('testvalue', $data['requests-testcookie']);
}
public function domainMatchProvider() {
return array(
array('example.com', 'example.com', true, true),
array('example.com', 'www.example.com', false, true),
array('example.com', 'example.net', false, false),
// Leading period
array('.example.com', 'example.com', true, true),
array('.example.com', 'www.example.com', false, true),
array('.example.com', 'example.net', false, false),
// Prefix, but not subdomain
array('example.com', 'notexample.com', false, false),
array('example.com', 'notexample.net', false, false),
// Reject IP address prefixes
array('127.0.0.1', '127.0.0.1', true, true),
array('127.0.0.1', 'abc.127.0.0.1', false, false),
array('127.0.0.1', 'example.com', false, false),
// Check that we're checking the actual length
array('127.com', 'test.127.com', false, true),
);
}
/**
* @dataProvider domainMatchProvider
*/
public function testDomainExactMatch($original, $check, $matches, $domain_matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = $original;
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->domain_matches($check));
}
/**
* @dataProvider domainMatchProvider
*/
public function testDomainMatch($original, $check, $matches, $domain_matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = $original;
$flags = array(
'host-only' => false
);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
$this->assertEquals($domain_matches, $cookie->domain_matches($check));
}
public function pathMatchProvider() {
return array(
array('/', '', true),
array('/', '/', true),
array('/', '/test', true),
array('/', '/test/', true),
array('/test', '/', false),
array('/test', '/test', true),
array('/test', '/testing', false),
array('/test', '/test/', true),
array('/test', '/test/ing', true),
array('/test', '/test/ing/', true),
array('/test/', '/test/', true),
array('/test/', '/', false),
);
}
/**
* @dataProvider pathMatchProvider
*/
public function testPathMatch($original, $check, $matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['path'] = $original;
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->path_matches($check));
}
public function urlMatchProvider() {
return array(
// Domain handling
array( 'example.com', '/', 'http://example.com/', true, true ),
array( 'example.com', '/', 'http://www.example.com/', false, true ),
array( 'example.com', '/', 'http://example.net/', false, false ),
array( 'example.com', '/', 'http://www.example.net/', false, false ),
// /test
array( 'example.com', '/test', 'http://example.com/', false, false ),
array( 'example.com', '/test', 'http://www.example.com/', false, false ),
array( 'example.com', '/test', 'http://example.com/test', true, true ),
array( 'example.com', '/test', 'http://www.example.com/test', false, true ),
array( 'example.com', '/test', 'http://example.com/testing', false, false ),
array( 'example.com', '/test', 'http://www.example.com/testing', false, false ),
array( 'example.com', '/test', 'http://example.com/test/', true, true ),
array( 'example.com', '/test', 'http://www.example.com/test/', false, true ),
// /test/
array( 'example.com', '/test/', 'http://example.com/', false, false ),
array( 'example.com', '/test/', 'http://www.example.com/', false, false ),
);
}
/**
* @depends testDomainExactMatch
* @depends testPathMatch
* @dataProvider urlMatchProvider
*/
public function testUrlExactMatch($domain, $path, $check, $matches, $domain_matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = $domain;
$attributes['path'] = $path;
$check = new Requests_IRI($check);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes);
$this->assertEquals($matches, $cookie->uri_matches($check));
}
/**
* @depends testDomainMatch
* @depends testPathMatch
* @dataProvider urlMatchProvider
*/
public function testUrlMatch($domain, $path, $check, $matches, $domain_matches) {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = $domain;
$attributes['path'] = $path;
$flags = array(
'host-only' => false
);
$check = new Requests_IRI($check);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
$this->assertEquals($domain_matches, $cookie->uri_matches($check));
}
public function testUrlMatchSecure() {
$attributes = new Requests_Utility_CaseInsensitiveDictionary();
$attributes['domain'] = 'example.com';
$attributes['path'] = '/';
$attributes['secure'] = true;
$flags = array(
'host-only' => false,
);
$cookie = new Requests_Cookie('requests-testcookie', 'testvalue', $attributes, $flags);
$this->assertTrue($cookie->uri_matches(new Requests_IRI('https://example.com/')));
$this->assertFalse($cookie->uri_matches(new Requests_IRI('http://example.com/')));
// Double-check host-only
$this->assertTrue($cookie->uri_matches(new Requests_IRI('https://www.example.com/')));
$this->assertFalse($cookie->uri_matches(new Requests_IRI('http://www.example.com/')));
}
/**
* 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->domain_matches('example.com'));
$this->assertTrue($cookie->domain_matches('example.net'));
$this->assertTrue($cookie->path_matches('/'));
$this->assertTrue($cookie->path_matches('/test'));
$this->assertTrue($cookie->path_matches('/test/'));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/')));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/test')));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.com/test/')));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/')));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/test')));
$this->assertTrue($cookie->uri_matches(new Requests_IRI('http://example.net/test/')));
}
public static function parseResultProvider() {
return array(
// Basic parsing
array(
'foo=bar',
array( 'name' => 'foo', 'value' => 'bar' ),
),
array(
'bar',
array( 'name' => '', 'value' => 'bar' ),
),
// Expiration
// RFC 822, updated by RFC 1123
array(
'foo=bar; Expires=Thu, 5-Dec-2013 04:50:12 GMT',
array( 'expired' => true ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
),
array(
'foo=bar; Expires=Fri, 5-Dec-2014 04:50:12 GMT',
array( 'expired' => false ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
),
// RFC 850, obsoleted by RFC 1036
array(
'foo=bar; Expires=Thursday, 5-Dec-2013 04:50:12 GMT',
array( 'expired' => true ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
),
array(
'foo=bar; Expires=Friday, 5-Dec-2014 04:50:12 GMT',
array( 'expired' => false ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
),
// asctime()
array(
'foo=bar; Expires=Thu Dec 5 04:50:12 2013',
array( 'expired' => true ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2013 ) ),
),
array(
'foo=bar; Expires=Fri Dec 5 04:50:12 2014',
array( 'expired' => false ),
array( 'expires' => gmmktime( 4, 50, 12, 12, 5, 2014 ) ),
),
array(
// Invalid
'foo=bar; Expires=never',
array(),
array( 'expires' => null ),
),
// Max-Age
array(
'foo=bar; Max-Age=10',
array( 'expired' => false ),
array( 'max-age' => gmmktime( 0, 0, 10, 1, 1, 2014 ) ),
),
array(
'foo=bar; Max-Age=3660',
array( 'expired' => false ),
array( 'max-age' => gmmktime( 1, 1, 0, 1, 1, 2014 ) ),
),
array(
'foo=bar; Max-Age=0',
array( 'expired' => true ),
array( 'max-age' => 0 ),
),
array(
'foo=bar; Max-Age=-1000',
array( 'expired' => true ),
array( 'max-age' => 0 ),
),
array(
// Invalid (non-digit character)
'foo=bar; Max-Age=1e6',
array( 'expired' => false ),
array( 'max-age' => null ),
)
);
}
protected function check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags = array()) {
if (isset($expected['name'])) {
$this->assertEquals($expected['name'], $cookie->name);
}
if (isset($expected['value'])) {
$this->assertEquals($expected['value'], $cookie->value);
}
if (isset($expected['expired'])) {
$this->assertEquals($expected['expired'], $cookie->is_expired());
}
if (isset($expected_attributes)) {
foreach ($expected_attributes as $attr_key => $attr_val) {
$this->assertEquals($attr_val, $cookie->attributes[$attr_key], "$attr_key should match supplied");
}
}
if (isset($expected_flags)) {
foreach ($expected_flags as $flag_key => $flag_val) {
$this->assertEquals($flag_val, $cookie->flags[$flag_key], "$flag_key should match supplied");
}
}
}
/**
* @dataProvider parseResultProvider
*/
public function testParsingHeader($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
// Set the reference time to 2014-01-01 00:00:00
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
$cookie = Requests_Cookie::parse($header, null, $reference_time);
$this->check_parsed_cookie($cookie, $expected, $expected_attributes);
}
/**
* Double-normalizes the cookie data to ensure we catch any issues there
*
* @dataProvider parseResultProvider
*/
public function testParsingHeaderDouble($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
// Set the reference time to 2014-01-01 00:00:00
$reference_time = gmmktime( 0, 0, 0, 1, 1, 2014 );
$cookie = Requests_Cookie::parse($header, null, $reference_time);
// Normalize the value again
$cookie->normalize();
$this->check_parsed_cookie($cookie, $expected, $expected_attributes, $expected_flags);
}
/**
* @dataProvider parseResultProvider
*/
public function testParsingHeaderObject($header, $expected, $expected_attributes = array(), $expected_flags = array()) {
$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, null, $reference_time);
$this->assertCount(1, $parsed);
$cookie = reset($parsed);
$this->check_parsed_cookie($cookie, $expected, $expected_attributes);
}
public function parseFromHeadersProvider() {
return array(
# Varying origin path
array(
'name=value',
'http://example.com/',
array(),
array( 'path' => '/' ),
array( 'host-only' => true ),
),
array(
'name=value',
'http://example.com/test',
array(),
array( 'path' => '/' ),
array( 'host-only' => true ),
),
array(
'name=value',
'http://example.com/test/',
array(),
array( 'path' => '/test' ),
array( 'host-only' => true ),
),
array(
'name=value',
'http://example.com/test/abc',
array(),
array( 'path' => '/test' ),
array( 'host-only' => true ),
),
array(
'name=value',
'http://example.com/test/abc/',
array(),
array( 'path' => '/test/abc' ),
array( 'host-only' => true ),
),
# With specified path
array(
'name=value; path=/',
'http://example.com/',
array(),
array( 'path' => '/' ),
array( 'host-only' => true ),
),
array(
'name=value; path=/test',
'http://example.com/',
array(),
array( 'path' => '/test' ),
array( 'host-only' => true ),
),
array(
'name=value; path=/test/',
'http://example.com/',
array(),
array( 'path' => '/test/' ),
array( 'host-only' => true ),
),
# Invalid path
array(
'name=value; path=yolo',
'http://example.com/',
array(),
array( 'path' => '/' ),
array( 'host-only' => true ),
),
array(
'name=value; path=yolo',
'http://example.com/test/',
array(),
array( 'path' => '/test' ),
array( 'host-only' => true ),
),
# Cross-origin cookies, reject!
array(
'name=value; domain=example.org',
'http://example.com/',
array( 'invalid' => false ),
),
# Subdomain cookies
array(
'name=value; domain=test.example.com',
'http://test.example.com/',
array(),
array( 'domain' => 'test.example.com' ),
array( 'host-only' => false )
),
array(
'name=value; domain=example.com',
'http://test.example.com/',
array(),
array( 'domain' => 'example.com' ),
array( 'host-only' => false )
),
);
}
/**
* @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);
}
}

0
vendor/rmccue/requests/tests/IDNAEncoder.php vendored Executable file → Normal file
View file

87
vendor/rmccue/requests/tests/IRI.php vendored Executable file → Normal file
View file

@ -51,7 +51,7 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array('./g', 'http://a/b/c/g'),
array('g/', 'http://a/b/c/g/'),
array('/g', 'http://a/g'),
array('//g', 'http://g'),
array('//g', 'http://g/'),
array('?y', 'http://a/b/c/d;p?y'),
array('g?y', 'http://a/b/c/g?y'),
array('#s', 'http://a/b/c/d;p?q#s'),
@ -66,8 +66,8 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array('..', 'http://a/b/'),
array('../', 'http://a/b/'),
array('../g', 'http://a/b/g'),
array('../..', 'http://a'),
array('../../', 'http://a'),
array('../..', 'http://a/'),
array('../../', 'http://a/'),
array('../../g', 'http://a/g'),
// Abnormal
array('../../../g', 'http://a/g'),
@ -132,14 +132,14 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array('http://a/b', 'c', 'http://a/c'),
array('http://a/b/', "c\x0Ad", 'http://a/b/c%0Ad'),
array('http://a/b/', "c\x0A\x0B", 'http://a/b/c%0A%0B'),
array('http://a/b/c', '//0', 'http://0'),
array('http://a/b/c', '//0', 'http://0/'),
array('http://a/b/c', '0', 'http://a/b/0'),
array('http://a/b/c', '?0', 'http://a/b/c?0'),
array('http://a/b/c', '#0', 'http://a/b/c#0'),
array('http://0/b/c', 'd', 'http://0/b/d'),
array('http://a/b/c?0', 'd', 'http://a/b/d'),
array('http://a/b/c#0', 'd', 'http://a/b/d'),
array('http://example.com', '//example.net', 'http://example.net'),
array('http://example.com', '//example.net', 'http://example.net/'),
array('http:g', 'a', 'http:a'),
);
}
@ -168,7 +168,7 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
{
return array(
array('http://example.com/', 'foo/111:bar', 'http://example.com/foo/111:bar'),
array('http://example.com/#foo', '', 'http://example.com'),
array('http://example.com/#foo', '', 'http://example.com/'),
);
}
@ -201,38 +201,38 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array('example://A/', 'example://a/'),
array('example://a/', 'example://a/'),
array('example://%25A/', 'example://%25a/'),
array('HTTP://EXAMPLE.com/', 'http://example.com'),
array('http://example.com/', 'http://example.com'),
array('http://example.com:', 'http://example.com'),
array('http://example.com:80', 'http://example.com'),
array('http://@example.com', 'http://@example.com'),
array('http://', 'http://'),
array('http://example.com?', 'http://example.com?'),
array('http://example.com#', 'http://example.com#'),
array('https://example.com/', 'https://example.com'),
array('https://example.com:', 'https://example.com'),
array('https://@example.com', 'https://@example.com'),
array('https://example.com?', 'https://example.com?'),
array('https://example.com#', 'https://example.com#'),
array('HTTP://EXAMPLE.com/', 'http://example.com/'),
array('http://example.com/', 'http://example.com/'),
array('http://example.com:', 'http://example.com/'),
array('http://example.com:80', 'http://example.com/'),
array('http://@example.com', 'http://@example.com/'),
array('http://', 'http:///'),
array('http://example.com?', 'http://example.com/?'),
array('http://example.com#', 'http://example.com/#'),
array('https://example.com/', 'https://example.com/'),
array('https://example.com:', 'https://example.com/'),
array('https://@example.com', 'https://@example.com/'),
array('https://example.com?', 'https://example.com/?'),
array('https://example.com#', 'https://example.com/#'),
array('file://localhost/foobar', 'file:/foobar'),
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]'),
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]'),
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]'),
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]'),
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]'),
array('http://[0:0:0:0:0:0:0:1]', 'http://[::1]/'),
array('http://[2001:db8:85a3:0000:0000:8a2e:370:7334]', 'http://[2001:db8:85a3::8a2e:370:7334]/'),
array('http://[0:0:0:0:0:ffff:c0a8:a01]', 'http://[::ffff:c0a8:a01]/'),
array('http://[ffff:0:0:0:0:0:0:0]', 'http://[ffff::]/'),
array('http://[::ffff:192.0.2.128]', 'http://[::ffff:192.0.2.128]/'),
array('http://[invalid]', 'http:'),
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]'),
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]'),
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234'),
array('http://[0:0:0:0:0:0:0:1]:', 'http://[::1]/'),
array('http://[0:0:0:0:0:0:0:1]:80', 'http://[::1]/'),
array('http://[0:0:0:0:0:0:0:1]:1234', 'http://[::1]:1234/'),
// Punycode decoding helps with normalisation of IRIs, but is not
// needed for URIs, so we don't really care about it for Requests
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv'),
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv'),
array('http://Aa@example.com', 'http://Aa@example.com'),
array('http://example.com?Aa', 'http://example.com?Aa'),
//array('http://xn--tdali-d8a8w.lv', 'http://tūdaliņ.lv/'),
//array('http://t%C5%ABdali%C5%86.lv', 'http://tūdaliņ.lv/'),
array('http://Aa@example.com', 'http://Aa@example.com/'),
array('http://example.com?Aa', 'http://example.com/?Aa'),
array('http://example.com/Aa', 'http://example.com/Aa'),
array('http://example.com#Aa', 'http://example.com#Aa'),
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]'),
array('http://example.com#Aa', 'http://example.com/#Aa'),
array('http://[0:0:0:0:0:0:0:0]', 'http://[::]/'),
array('http:.', 'http:'),
array('http:..', 'http:'),
array('http:./', 'http:'),
@ -249,15 +249,15 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array("http://example.com/\xF3\xB0\x80\x80", 'http://example.com/%F3%B0%80%80'),
array("http://example.com/\xF3\xB0\x80\x80%00", 'http://example.com/%F3%B0%80%80%00'),
array("http://example.com/\xF3\xB0\x80\x80a", 'http://example.com/%F3%B0%80%80a'),
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com?\xF3\xB0\x80\x80"),
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com?\xF3\xB0\x80\x80%00"),
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com?\xF3\xB0\x80\x80a"),
array("http://example.com?\xF3\xB0\x80\x80", "http://example.com/?\xF3\xB0\x80\x80"),
array("http://example.com?\xF3\xB0\x80\x80%00", "http://example.com/?\xF3\xB0\x80\x80%00"),
array("http://example.com?\xF3\xB0\x80\x80a", "http://example.com/?\xF3\xB0\x80\x80a"),
array("http://example.com/\xEE\x80\x80", 'http://example.com/%EE%80%80'),
array("http://example.com/\xEE\x80\x80%00", 'http://example.com/%EE%80%80%00'),
array("http://example.com/\xEE\x80\x80a", 'http://example.com/%EE%80%80a'),
array("http://example.com?\xEE\x80\x80", "http://example.com?\xEE\x80\x80"),
array("http://example.com?\xEE\x80\x80%00", "http://example.com?\xEE\x80\x80%00"),
array("http://example.com?\xEE\x80\x80a", "http://example.com?\xEE\x80\x80a"),
array("http://example.com?\xEE\x80\x80", "http://example.com/?\xEE\x80\x80"),
array("http://example.com?\xEE\x80\x80%00", "http://example.com/?\xEE\x80\x80%00"),
array("http://example.com?\xEE\x80\x80a", "http://example.com/?\xEE\x80\x80a"),
array("http://example.com/\xC2", 'http://example.com/%C2'),
array("http://example.com/\xC2a", 'http://example.com/%C2a'),
array("http://example.com/\xC2\x00", 'http://example.com/%C2%00'),
@ -268,8 +268,8 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
array("http://example.com/\xFF%00", 'http://example.com/%FF%00'),
array("http://example.com/\xFFa", 'http://example.com/%FFa'),
array('http://example.com/%61', 'http://example.com/a'),
array('http://example.com?%26', 'http://example.com?%26'),
array('http://example.com?%61', 'http://example.com?a'),
array('http://example.com?%26', 'http://example.com/?%26'),
array('http://example.com?%61', 'http://example.com/?a'),
array('///', '///'),
);
}
@ -333,11 +333,6 @@ class RequestsTest_IRI extends PHPUnit_Framework_TestCase
$this->assertFalse(Requests_IRI::absolutize('://not a URL', '../'));
}
public function testInvalidAbsolutizeRelative()
{
$this->assertFalse(Requests_IRI::absolutize('http://example.com/', 'http://example.com//not a URL'));
}
public function testFullGamut()
{
$iri = new Requests_IRI();

View file

@ -0,0 +1,131 @@
<?php
class RequestsTest_Proxy_HTTP extends PHPUnit_Framework_TestCase {
protected function checkProxyAvailable($type = '') {
switch ($type) {
case 'auth':
$has_proxy = defined('REQUESTS_HTTP_PROXY_AUTH') && REQUESTS_HTTP_PROXY_AUTH;
break;
default:
$has_proxy = defined('REQUESTS_HTTP_PROXY') && REQUESTS_HTTP_PROXY;
break;
}
if (!$has_proxy) {
$this->markTestSkipped('Proxy not available');
}
}
public function transportProvider() {
return array(
array('Requests_Transport_cURL'),
array('Requests_Transport_fsockopen'),
);
}
/**
* @dataProvider transportProvider
*/
public function testConnectWithString($transport) {
$this->checkProxyAvailable();
$options = array(
'proxy' => REQUESTS_HTTP_PROXY,
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals('http', $response->headers['x-requests-proxied']);
$data = json_decode($response->body, true);
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
}
/**
* @dataProvider transportProvider
*/
public function testConnectWithArray($transport) {
$this->checkProxyAvailable();
$options = array(
'proxy' => array(REQUESTS_HTTP_PROXY),
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals('http', $response->headers['x-requests-proxied']);
$data = json_decode($response->body, true);
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
}
/**
* @dataProvider transportProvider
* @expectedException Requests_Exception
*/
public function testConnectInvalidParameters($transport) {
$this->checkProxyAvailable();
$options = array(
'proxy' => array(REQUESTS_HTTP_PROXY, 'testuser', 'password', 'something'),
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
}
/**
* @dataProvider transportProvider
*/
public function testConnectWithInstance($transport) {
$this->checkProxyAvailable();
$options = array(
'proxy' => new Requests_Proxy_HTTP(REQUESTS_HTTP_PROXY),
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals('http', $response->headers['x-requests-proxied']);
$data = json_decode($response->body, true);
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
}
/**
* @dataProvider transportProvider
*/
public function testConnectWithAuth($transport) {
$this->checkProxyAvailable('auth');
$options = array(
'proxy' => array(
REQUESTS_HTTP_PROXY_AUTH,
REQUESTS_HTTP_PROXY_AUTH_USER,
REQUESTS_HTTP_PROXY_AUTH_PASS
),
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals(200, $response->status_code);
$this->assertEquals('http', $response->headers['x-requests-proxied']);
$data = json_decode($response->body, true);
$this->assertEquals('http', $data['headers']['x-requests-proxy']);
}
/**
* @dataProvider transportProvider
*/
public function testConnectWithInvalidAuth($transport) {
$this->checkProxyAvailable('auth');
$options = array(
'proxy' => array(
REQUESTS_HTTP_PROXY_AUTH,
REQUESTS_HTTP_PROXY_AUTH_USER . '!',
REQUESTS_HTTP_PROXY_AUTH_PASS . '!'
),
'transport' => $transport,
);
$response = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals(407, $response->status_code);
}
}

26
vendor/rmccue/requests/tests/Requests.php vendored Executable file → Normal file
View file

@ -9,7 +9,7 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
}
public function testDefaultTransport() {
$request = Requests::get('http://httpbin.org/get');
$request = Requests::get(httpbin('/get'));
$this->assertEquals(200, $request->status_code);
}
@ -51,6 +51,20 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
}
}
public function testProtocolVersionParsing() {
$transport = new RawTransport();
$transport->data =
"HTTP/1.0 200 OK\r\n".
"Host: localhost\r\n\r\n";
$options = array(
'transport' => $transport
);
$response = Requests::get('http://example.com/', array(), $options);
$this->assertEquals(1.0, $response->protocol_version);
}
public function testRawAccess() {
$transport = new RawTransport();
$transport->data =
@ -137,4 +151,12 @@ class RequestsTest_Requests extends PHPUnit_Framework_TestCase {
$this->assertEquals(302, $response->status_code);
$this->assertEquals(0, $response->redirects);
}
}
/**
* @expectedException Requests_Exception
*/
public function testTimeoutException() {
$options = array('timeout' => 0.5);
$response = Requests::get(httpbin('/delay/3'), array(), $options);
}
}

0
vendor/rmccue/requests/tests/Response/Headers.php vendored Executable file → Normal file
View file

0
vendor/rmccue/requests/tests/SSL.php vendored Executable file → Normal file
View file

157
vendor/rmccue/requests/tests/Session.php vendored Executable file → Normal file
View file

@ -1,6 +1,147 @@
<?php
class RequestsTest_Session extends PHPUnit_Framework_TestCase {
public function testURLResolution() {
$session = new Requests_Session(httpbin('/'));
// Set the cookies up
$response = $session->get('/get');
$this->assertTrue($response->success);
$this->assertEquals(httpbin('/get'), $response->url);
$data = json_decode($response->body, true);
$this->assertNotNull($data);
$this->assertArrayHasKey('url', $data);
$this->assertEquals(httpbin('/get'), $data['url']);
}
public function testBasicGET() {
$session_headers = array(
'X-Requests-Session' => 'BasicGET',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->get('/get', array('X-Requests-Request' => 'GET'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
$data = json_decode($response->body, true);
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
$this->assertEquals('BasicGET', $data['headers']['X-Requests-Session']);
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
$this->assertEquals('GET', $data['headers']['X-Requests-Request']);
}
public function testBasicHEAD() {
$session_headers = array(
'X-Requests-Session' => 'BasicHEAD',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->head('/get', array('X-Requests-Request' => 'HEAD'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
}
public function testBasicDELETE() {
$session_headers = array(
'X-Requests-Session' => 'BasicDELETE',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->delete('/delete', array('X-Requests-Request' => 'DELETE'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
$data = json_decode($response->body, true);
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
$this->assertEquals('BasicDELETE', $data['headers']['X-Requests-Session']);
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
$this->assertEquals('DELETE', $data['headers']['X-Requests-Request']);
}
public function testBasicPOST() {
$session_headers = array(
'X-Requests-Session' => 'BasicPOST',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->post('/post', array('X-Requests-Request' => 'POST'), array('postdata' => 'exists'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
$data = json_decode($response->body, true);
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
$this->assertEquals('BasicPOST', $data['headers']['X-Requests-Session']);
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
$this->assertEquals('POST', $data['headers']['X-Requests-Request']);
}
public function testBasicPUT() {
$session_headers = array(
'X-Requests-Session' => 'BasicPUT',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->put('/put', array('X-Requests-Request' => 'PUT'), array('postdata' => 'exists'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
$data = json_decode($response->body, true);
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
$this->assertEquals('BasicPUT', $data['headers']['X-Requests-Session']);
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
$this->assertEquals('PUT', $data['headers']['X-Requests-Request']);
}
public function testBasicPATCH() {
$session_headers = array(
'X-Requests-Session' => 'BasicPATCH',
'X-Requests-Request' => 'notset',
);
$session = new Requests_Session(httpbin('/'), $session_headers);
$response = $session->patch('/patch', array('X-Requests-Request' => 'PATCH'), array('postdata' => 'exists'));
$response->throw_for_status(false);
$this->assertEquals(200, $response->status_code);
$data = json_decode($response->body, true);
$this->assertArrayHasKey('X-Requests-Session', $data['headers']);
$this->assertEquals('BasicPATCH', $data['headers']['X-Requests-Session']);
$this->assertArrayHasKey('X-Requests-Request', $data['headers']);
$this->assertEquals('PATCH', $data['headers']['X-Requests-Request']);
}
public function testMultiple() {
$session = new Requests_Session(httpbin('/'), array('X-Requests-Session' => 'Multiple'));
$requests = array(
'test1' => array(
'url' => httpbin('/get')
),
'test2' => array(
'url' => httpbin('/get')
),
);
$responses = $session->request_multiple($requests);
// test1
$this->assertNotEmpty($responses['test1']);
$this->assertInstanceOf('Requests_Response', $responses['test1']);
$this->assertEquals(200, $responses['test1']->status_code);
$result = json_decode($responses['test1']->body, true);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
// test2
$this->assertNotEmpty($responses['test2']);
$this->assertInstanceOf('Requests_Response', $responses['test2']);
$this->assertEquals(200, $responses['test2']->status_code);
$result = json_decode($responses['test2']->body, true);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
}
public function testPropertyUsage() {
$headers = array(
'X-TestHeader' => 'testing',
@ -46,22 +187,8 @@ class RequestsTest_Session extends PHPUnit_Framework_TestCase {
$this->assertNull($session->invalidoption);
}
public function testURLResolution() {
$session = new Requests_Session('http://httpbin.org/');
// Set the cookies up
$response = $session->get('/get');
$this->assertTrue($response->success);
$this->assertEquals('http://httpbin.org/get', $response->url);
$data = json_decode($response->body, true);
$this->assertNotNull($data);
$this->assertArrayHasKey('url', $data);
$this->assertEquals('http://httpbin.org/get', $data['url']);
}
public function testSharedCookies() {
$session = new Requests_Session('http://httpbin.org/');
$session = new Requests_Session(httpbin('/'));
$options = array(
'follow_redirects' => false

315
vendor/rmccue/requests/tests/Transport/Base.php vendored Executable file → Normal file
View file

@ -25,21 +25,42 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
return $options;
}
public function testResponseByteLimit() {
$limit = 104;
$options = array(
'max_bytes' => $limit,
);
$response = Requests::get(httpbin('/bytes/325'), array(), $this->getOptions($options));
$this->assertEquals($limit, strlen($response->body));
}
public function testResponseByteLimitWithFile() {
$limit = 300;
$options = array(
'max_bytes' => $limit,
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
);
$response = Requests::get(httpbin('/bytes/482'), array(), $this->getOptions($options));
$this->assertEmpty($response->body);
$this->assertEquals($limit, filesize($options['filename']));
unlink($options['filename']);
}
public function testSimpleGET() {
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions());
$request = Requests::get(httpbin('/get'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
}
public function testGETWithArgs() {
$request = Requests::get('http://httpbin.org/get?test=true&test2=test', array(), $this->getOptions());
$request = Requests::get(httpbin('/get?test=true&test2=test'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}
@ -48,16 +69,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test' => 'true',
'test2' => 'test',
);
$request = Requests::request('http://httpbin.org/get', array(), $data, Requests::GET, $this->getOptions());
$request = Requests::request(httpbin('/get'), array(), $data, Requests::GET, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}
public function testGETWithNestedData() {
$this->markTestSkipped('httpbin changed their data format; this test will now fail');
$data = array(
'test' => 'true',
'test2' => array(
@ -65,11 +85,11 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test4' => 'test-too',
),
);
$request = Requests::request('http://httpbin.org/get', array(), $data, Requests::GET, $this->getOptions());
$request = Requests::request(httpbin('/get'), array(), $data, Requests::GET, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too', $result['url']);
$this->assertEquals(httpbin('/get?test=true&test2%5Btest3%5D=test&test2%5Btest4%5D=test-too'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2[test3]' => 'test', 'test2[test4]' => 'test-too'), $result['args']);
}
@ -77,11 +97,11 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$data = array(
'test2' => 'test',
);
$request = Requests::request('http://httpbin.org/get?test=true', array(), $data, Requests::GET, $this->getOptions());
$request = Requests::request(httpbin('/get?test=true'), array(), $data, Requests::GET, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get?test=true&test2=test', $result['url']);
$this->assertEquals(httpbin('/get?test=true&test2=test'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}
@ -89,7 +109,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$headers = array(
'Requested-At' => time(),
);
$request = Requests::get('http://httpbin.org/get', $headers, $this->getOptions());
$request = Requests::get(httpbin('/get'), $headers, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -97,23 +117,28 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
}
public function testChunked() {
$request = Requests::get('http://httpbin.org/stream/1', array(), $this->getOptions());
$request = Requests::get(httpbin('/stream/1'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/stream/1', $result['url']);
$this->assertEquals(httpbin('/stream/1'), $result['url']);
$this->assertEmpty($result['args']);
}
public function testHEAD() {
$request = Requests::head('http://httpbin.org/get', array(), $this->getOptions());
$request = Requests::head(httpbin('/get'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$this->assertEquals('', $request->body);
}
public function testTRACE() {
$request = Requests::trace(httpbin('/trace'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
}
public function testRawPOST() {
$data = 'test';
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -122,7 +147,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testFormPost() {
$data = 'test=true&test2=test';
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -134,7 +159,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test' => 'true',
'test2' => 'test',
);
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -149,7 +174,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test4' => 'test-too',
),
);
$request = Requests::post('http://httpbin.org/post', array(), $data, $this->getOptions());
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -158,7 +183,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testRawPUT() {
$data = 'test';
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -167,7 +192,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testFormPUT() {
$data = 'test=true&test2=test';
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -179,7 +204,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test' => 'true',
'test2' => 'test',
);
$request = Requests::put('http://httpbin.org/put', array(), $data, $this->getOptions());
$request = Requests::put(httpbin('/put'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -188,7 +213,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testRawPATCH() {
$data = 'test';
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
@ -197,7 +222,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testFormPATCH() {
$data = 'test=true&test2=test';
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code, $request->body);
$result = json_decode($request->body, true);
@ -209,19 +234,24 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test' => 'true',
'test2' => 'test',
);
$request = Requests::patch('http://httpbin.org/patch', array(), $data, $this->getOptions());
$request = Requests::patch(httpbin('/patch'), array(), $data, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
}
public function testOPTIONS() {
$request = Requests::options(httpbin('/options'), array(), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
}
public function testDELETE() {
$request = Requests::delete('http://httpbin.org/delete', array(), $this->getOptions());
$request = Requests::delete(httpbin('/delete'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/delete', $result['url']);
$this->assertEquals(httpbin('/delete'), $result['url']);
$this->assertEmpty($result['args']);
}
@ -230,23 +260,40 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
'test' => 'true',
'test2' => 'test',
);
$request = Requests::request('http://httpbin.org/delete', array(), $data, Requests::DELETE, $this->getOptions());
$request = Requests::request(httpbin('/delete'), array(), $data, Requests::DELETE, $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/delete?test=true&test2=test', $result['url']);
$this->assertEquals(httpbin('/delete?test=true&test2=test'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['args']);
}
public function testLOCK() {
$request = Requests::request(httpbin('/lock'), array(), array(), 'LOCK', $this->getOptions());
$this->assertEquals(200, $request->status_code);
}
public function testLOCKWithData() {
$data = array(
'test' => 'true',
'test2' => 'test',
);
$request = Requests::request(httpbin('/lock'), array(), $data, 'LOCK', $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
}
public function testRedirects() {
$request = Requests::get('http://httpbin.org/redirect/6', array(), $this->getOptions());
$request = Requests::get(httpbin('/redirect/6'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$this->assertEquals(6, $request->redirects);
}
public function testRelativeRedirects() {
$request = Requests::get('http://httpbin.org/relative-redirect/6', array(), $this->getOptions());
$request = Requests::get(httpbin('/relative-redirect/6'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$this->assertEquals(6, $request->redirects);
@ -260,7 +307,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$options = array(
'redirects' => 10, // default, but force just in case
);
$request = Requests::get('http://httpbin.org/redirect/11', array(), $this->getOptions($options));
$request = Requests::get(httpbin('/redirect/11'), array(), $this->getOptions($options));
}
public static function statusCodeSuccessProvider() {
@ -316,11 +363,16 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCode($code, $success) {
$url = sprintf('http://httpbin.org/status/%d', $code);
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$this->assertEquals($code, $request->status_code);
$this->assertEquals($success, $request->success);
}
@ -329,20 +381,24 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCodeThrow($code, $success) {
$url = sprintf('http://httpbin.org/status/%d', $code);
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
if (!$success) {
if ($code >= 400) {
$this->setExpectedException('Requests_Exception_HTTP_' . $code, $code);
$this->setExpectedException('Requests_Exception_HTTP_' . $code, '', $code);
}
elseif ($code >= 300 && $code < 400) {
$this->setExpectedException('Requests_Exception');
}
}
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$request->throw_for_status(false);
}
@ -350,22 +406,33 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
* @dataProvider statusCodeSuccessProvider
*/
public function testStatusCodeThrowAllowRedirects($code, $success) {
$url = sprintf('http://httpbin.org/status/%d', $code);
$transport = new MockTransport();
$transport->code = $code;
$url = sprintf(httpbin('/status/%d'), $code);
$options = array(
'follow_redirects' => false,
'transport' => $transport,
);
if (!$success) {
if ($code >= 400) {
$this->setExpectedException('Requests_Exception_HTTP_' . $code, $code);
if ($code >= 400 || $code === 304 || $code === 305 || $code === 306) {
$this->setExpectedException('Requests_Exception_HTTP_' . $code, '', $code);
}
}
$request = Requests::get($url, array(), $this->getOptions($options));
$request = Requests::get($url, array(), $options);
$request->throw_for_status(true);
}
public function testStatusCodeUnknown(){
$request = Requests::get('http://httpbin.org/status/599', array(), $this->getOptions());
$transport = new MockTransport();
$transport->code = 599;
$options = array(
'transport' => $transport,
);
$request = Requests::get(httpbin('/status/599'), array(), $options);
$this->assertEquals(599, $request->status_code);
$this->assertEquals(false, $request->success);
}
@ -374,12 +441,19 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
* @expectedException Requests_Exception_HTTP_Unknown
*/
public function testStatusCodeThrowUnknown(){
$request = Requests::get('http://httpbin.org/status/599', array(), $this->getOptions());
$transport = new MockTransport();
$transport->code = 599;
$options = array(
'transport' => $transport,
);
$request = Requests::get(httpbin('/status/599'), array(), $options);
$request->throw_for_status(true);
}
public function testGzipped() {
$request = Requests::get('http://httpbin.org/gzip', array(), $this->getOptions());
$request = Requests::get(httpbin('/gzip'), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body);
@ -390,13 +464,13 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$options = array(
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
);
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions($options));
$request = Requests::get(httpbin('/get'), array(), $this->getOptions($options));
$this->assertEquals(200, $request->status_code);
$this->assertEmpty($request->body);
$contents = file_get_contents($options['filename']);
$result = json_decode($contents, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
unlink($options['filename']);
@ -406,7 +480,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$options = array(
'blocking' => false
);
$request = Requests::get('http://httpbin.org/get', array(), $this->getOptions($options));
$request = Requests::get(httpbin('/get'), array(), $this->getOptions($options));
$empty = new Requests_Response();
$this->assertEquals($empty, $request);
}
@ -424,11 +498,12 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
return;
}
$request = Requests::get('https://httpbin.org/get', array(), $this->getOptions());
$request = Requests::get(httpbin('/get', true), array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
// Disable, since httpbin always returns http
// $this->assertEquals(httpbin('/get', true), $result['url']);
$this->assertEmpty($result['args']);
}
@ -459,10 +534,6 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
/**
* Test that SSL fails with a bad certificate
*
* This is defined as invalid by
* https://onlinessl.netlock.hu/en/test-center/invalid-ssl-certificate.html
* and is used in testing in PhantomJS. That said, expect this to break.
*
* @expectedException Requests_Exception
*/
public function testBadDomain() {
@ -471,15 +542,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
return;
}
$request = Requests::get('https://tv.eurosport.com/', array(), $this->getOptions());
$request = Requests::head('https://wrong.host.badssl.com/', array(), $this->getOptions());
}
/**
* Test that the transport supports Server Name Indication with HTTPS
*
* sni.velox.ch is used for SNI testing, and the common name is set to
* `*.sni.velox.ch` as such. Without alternate name support, this will fail
* as `sni.velox.ch` is only in the alternate name
* badssl.com is used for SSL testing, and the common name is set to
* `*.badssl.com` as such. Without alternate name support, this will fail
* as `badssl.com` is only in the alternate name
*/
public function testAlternateNameSupport() {
if ($this->skip_https) {
@ -487,16 +558,15 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
return;
}
$request = Requests::get('https://sni.velox.ch/', array(), $this->getOptions());
$request = Requests::head('https://badssl.com/', array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
}
/**
* Test that the transport supports Server Name Indication with HTTPS
*
* sni.velox.ch is used for SNI testing, and the common name is set to
* `*.sni.velox.ch` as such. Without SNI support, this will fail. Also tests
* our wildcard support.
* feelingrestful.com (owned by hmn.md and used with permission) points to
* CloudFlare, and will fail if SNI isn't sent.
*/
public function testSNISupport() {
if ($this->skip_https) {
@ -504,7 +574,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
return;
}
$request = Requests::get('https://abc.sni.velox.ch/', array(), $this->getOptions());
$request = Requests::head('https://feelingrestful.com/', array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
}
@ -515,17 +585,17 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$options = array(
'timeout' => 1,
);
$request = Requests::get('http://httpbin.org/delay/10', array(), $this->getOptions($options));
$request = Requests::get(httpbin('/delay/10'), array(), $this->getOptions($options));
var_dump($request);
}
public function testMultiple() {
$requests = array(
'test1' => array(
'url' => 'http://httpbin.org/get'
'url' => httpbin('/get')
),
'test2' => array(
'url' => 'http://httpbin.org/get'
'url' => httpbin('/get')
),
);
$responses = Requests::request_multiple($requests, $this->getOptions());
@ -536,7 +606,7 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $responses['test1']->status_code);
$result = json_decode($responses['test1']->body, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
// test2
@ -545,17 +615,17 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
$this->assertEquals(200, $responses['test2']->status_code);
$result = json_decode($responses['test2']->body, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
}
public function testMultipleWithDifferingMethods() {
$requests = array(
'get' => array(
'url' => 'http://httpbin.org/get',
'url' => httpbin('/get'),
),
'post' => array(
'url' => 'http://httpbin.org/post',
'url' => httpbin('/post'),
'type' => Requests::POST,
'data' => 'test',
),
@ -577,10 +647,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testMultipleWithFailure() {
$requests = array(
'success' => array(
'url' => 'http://httpbin.org/get',
'url' => httpbin('/get'),
),
'timeout' => array(
'url' => 'http://httpbin.org/delay/10',
'url' => httpbin('/delay/10'),
'options' => array(
'timeout' => 1,
),
@ -594,10 +664,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testMultipleUsingCallback() {
$requests = array(
'get' => array(
'url' => 'http://httpbin.org/get',
'url' => httpbin('/get'),
),
'post' => array(
'url' => 'http://httpbin.org/post',
'url' => httpbin('/post'),
'type' => Requests::POST,
'data' => 'test',
),
@ -615,10 +685,10 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testMultipleUsingCallbackAndFailure() {
$requests = array(
'success' => array(
'url' => 'http://httpbin.org/get',
'url' => httpbin('/get'),
),
'timeout' => array(
'url' => 'http://httpbin.org/delay/10',
'url' => httpbin('/delay/10'),
'options' => array(
'timeout' => 1,
),
@ -641,13 +711,13 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
public function testMultipleToFile() {
$requests = array(
'get' => array(
'url' => 'http://httpbin.org/get',
'url' => httpbin('/get'),
'options' => array(
'filename' => tempnam(sys_get_temp_dir(), 'RLT') // RequestsLibraryTest
),
),
'post' => array(
'url' => 'http://httpbin.org/post',
'url' => httpbin('/post'),
'type' => Requests::POST,
'data' => 'test',
'options' => array(
@ -660,24 +730,97 @@ abstract class RequestsTest_Transport_Base extends PHPUnit_Framework_TestCase {
// GET request
$contents = file_get_contents($requests['get']['options']['filename']);
$result = json_decode($contents, true);
$this->assertEquals('http://httpbin.org/get', $result['url']);
$this->assertEquals(httpbin('/get'), $result['url']);
$this->assertEmpty($result['args']);
unlink($requests['get']['options']['filename']);
// POST request
$contents = file_get_contents($requests['post']['options']['filename']);
$result = json_decode($contents, true);
$this->assertEquals('http://httpbin.org/post', $result['url']);
$this->assertEquals(httpbin('/post'), $result['url']);
$this->assertEquals('test', $result['data']);
unlink($requests['post']['options']['filename']);
}
public function testHostHeader() {
$request = Requests::get('http://portquiz.positon.org:8080/', array(), $this->getOptions());
$responseDoc = new DOMDocument;
$responseDoc->loadHTML($request->body);
$portXpath = new DOMXPath($responseDoc);
$portXpathMatches = $portXpath->query('//p/b');
$this->assertEquals(8080, $portXpathMatches->item(0)->nodeValue);
public function testAlternatePort() {
$request = Requests::get('http://portquiz.net:8080/', array(), $this->getOptions());
$this->assertEquals(200, $request->status_code);
$num = preg_match('#You have reached this page on port <b>(\d+)</b>#i', $request->body, $matches);
$this->assertEquals(1, $num, 'Response should contain the port number');
$this->assertEquals(8080, $matches[1]);
}
public function testProgressCallback() {
$mock = $this->getMockBuilder('stdClass')->setMethods(array('progress'))->getMock();
$mock->expects($this->atLeastOnce())->method('progress');
$hooks = new Requests_Hooks();
$hooks->register('request.progress', array($mock, 'progress'));
$options = array(
'hooks' => $hooks,
);
$options = $this->getOptions($options);
$response = Requests::get(httpbin('/get'), array(), $options);
}
public function testAfterRequestCallback() {
$mock = $this->getMockBuilder('stdClass')
->setMethods(array('after_request'))
->getMock();
$mock->expects($this->atLeastOnce())
->method('after_request')
->with(
$this->isType('string'),
$this->logicalAnd($this->isType('array'), $this->logicalNot($this->isEmpty()))
);
$hooks = new Requests_Hooks();
$hooks->register('curl.after_request', array($mock, 'after_request'));
$hooks->register('fsockopen.after_request', array($mock, 'after_request'));
$options = array(
'hooks' => $hooks,
);
$options = $this->getOptions($options);
$response = Requests::get(httpbin('/get'), array(), $options);
}
public function testReusableTransport() {
$options = $this->getOptions(array('transport' => new $this->transport()));
$request1 = Requests::get(httpbin('/get'), array(), $options);
$request2 = Requests::get(httpbin('/get'), array(), $options);
$this->assertEquals(200, $request1->status_code);
$this->assertEquals(200, $request2->status_code);
$result1 = json_decode($request1->body, true);
$result2 = json_decode($request2->body, true);
$this->assertEquals(httpbin('/get'), $result1['url']);
$this->assertEquals(httpbin('/get'), $result2['url']);
$this->assertEmpty($result1['args']);
$this->assertEmpty($result2['args']);
}
public function testQueryDataFormat() {
$data = array('test' => 'true', 'test2' => 'test');
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions(array('data_format' => 'query')));
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals(httpbin('/post').'?test=true&test2=test', $result['url']);
$this->assertEquals('', $result['data']);
}
public function testBodyDataFormat() {
$data = array('test' => 'true', 'test2' => 'test');
$request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions(array('data_format' => 'body')));
$this->assertEquals(200, $request->status_code);
$result = json_decode($request->body, true);
$this->assertEquals(httpbin('/post'), $result['url']);
$this->assertEquals(array('test' => 'true', 'test2' => 'test'), $result['form']);
}
}

0
vendor/rmccue/requests/tests/Transport/cURL.php vendored Executable file → Normal file
View file

0
vendor/rmccue/requests/tests/Transport/fsockopen.php vendored Executable file → Normal file
View file

33
vendor/rmccue/requests/tests/bootstrap.php vendored Executable file → Normal file
View file

@ -1,5 +1,26 @@
<?php
date_default_timezone_set('UTC');
function define_from_env($name, $default = false) {
$env = getenv($name);
if ($env) {
define($name, $env);
}
else {
define($name, $default);
}
}
define_from_env('REQUESTS_TEST_HOST', 'requests-php-tests.herokuapp.com');
define_from_env('REQUESTS_TEST_HOST_HTTP', REQUESTS_TEST_HOST);
define_from_env('REQUESTS_TEST_HOST_HTTPS', REQUESTS_TEST_HOST);
define_from_env('REQUESTS_HTTP_PROXY');
define_from_env('REQUESTS_HTTP_PROXY_AUTH');
define_from_env('REQUESTS_HTTP_PROXY_AUTH_USER');
define_from_env('REQUESTS_HTTP_PROXY_AUTH_PASS');
include(dirname(dirname(__FILE__)) . '/library/Requests.php');
Requests::register_autoloader();
@ -17,6 +38,11 @@ function autoload_tests($class) {
spl_autoload_register('autoload_tests');
function httpbin($suffix = '', $ssl = false) {
$host = $ssl ? 'https://' . REQUESTS_TEST_HOST_HTTPS : 'http://' . REQUESTS_TEST_HOST_HTTP;
return rtrim( $host, '/' ) . '/' . ltrim( $suffix, '/' );
}
class MockTransport implements Requests_Transport {
public $code = 200;
public $chunked = false;
@ -59,16 +85,21 @@ class MockTransport implements Requests_Transport {
415 => '415 Unsupported Media Type',
416 => '416 Requested Range Not Satisfiable',
417 => '417 Expectation Failed',
418 => '418 I\'m a teapot',
428 => '428 Precondition Required',
429 => '429 Too Many Requests',
431 => '431 Request Header Fields Too Large',
500 => '500 Internal Server Error',
501 => '501 Not Implemented',
502 => '502 Bad Gateway',
503 => '503 Service Unavailable',
504 => '504 Gateway Timeout',
505 => '505 HTTP Version Not Supported',
511 => '511 Network Authentication Required',
);
public function request($url, $headers = array(), $data = array(), $options = array()) {
$status = self::$messages[$this->code];
$status = isset(self::$messages[$this->code]) ? self::$messages[$this->code] : $this->code . ' unknown';
$response = "HTTP/1.0 $status\r\n";
$response .= "Content-Type: text/plain\r\n";
if ($this->chunked) {

4
vendor/rmccue/requests/tests/phpunit.xml.dist vendored Executable file → Normal file
View file

@ -7,6 +7,9 @@
<testsuite name="Transports">
<directory suffix=".php">Transport</directory>
</testsuite>
<testsuite name="Proxies">
<directory suffix=".php">Proxy</directory>
</testsuite>
<testsuite name="General">
<file>ChunkedEncoding.php</file>
<file>Cookies.php</file>
@ -14,6 +17,7 @@
<file>IRI.php</file>
<file>Requests.php</file>
<file>Response/Headers.php</file>
<file>Session.php</file>
<file>SSL.php</file>
</testsuite>
</testsuites>

View file

@ -0,0 +1,5 @@
def request(context, flow):
flow.request.headers["x-requests-proxy"] = "http"
def response(context, flow):
flow.response.headers[b"x-requests-proxied"] = "http"

View file

@ -0,0 +1,11 @@
PROXYDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
PORT=${PORT:-9000}
PROXYBIN=${PROXYBIN:-"$(which mitmdump)"}
ARGS="-s '$PROXYDIR/proxy.py' -p $PORT"
if [[ ! -z "$AUTH" ]]; then
ARGS="$ARGS --singleuser=$AUTH"
fi
PIDFILE="$PROXYDIR/proxy.pid"
start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --exec $PROXYBIN -- $ARGS

View file

@ -0,0 +1,5 @@
PROXYDIR="$PWD/$(dirname $0)"
PIDFILE="$PROXYDIR/proxy.pid"
start-stop-daemon --stop --pidfile $PIDFILE --make-pidfile && rm $PROXYDIR/proxy.pid