Пример #1
0
 public function testConstruct()
 {
     $request = new Request(array('host' => 'localhost', 'port' => 443, 'headers' => array('Header' => 'Value'), 'body' => array('Part 1'), 'params' => array('param' => 'value')));
     $expected = 'localhost';
     $result = $request->host;
     $this->assertEqual($expected, $result);
     $expected = 443;
     $result = $request->port;
     $this->assertEqual($expected, $result);
     $expected = 'GET';
     $result = $request->method;
     $this->assertEqual($expected, $result);
     $expected = 'HTTP/1.1';
     $result = $request->protocol;
     $this->assertEqual($expected, $result);
     $expected = '1.1';
     $result = $request->version;
     $this->assertEqual($expected, $result);
     $expected = '/';
     $result = $request->path;
     $this->assertEqual($expected, $result);
     $expected = array('param' => 'value');
     $result = $request->params;
     $this->assertEqual($expected, $result);
     $expected = array('Host: localhost:443', 'Connection: Close', 'User-Agent: Mozilla/5.0', 'Header: Value');
     $result = $request->headers();
     $this->assertEqual($expected, $result);
     $expected = array();
     $result = $request->cookies;
     $this->assertEqual($expected, $result);
     $expected = 'Part 1';
     $result = $request->body();
     $this->assertEqual($expected, $result);
 }
 public function testKeepDefinedContentTypeHeaderWhenTypeIsSet()
 {
     $request = new Request(array('method' => 'POST', 'type' => 'json', 'headers' => array('Content-Type' => 'text/x-test')));
     $expected = 'Content-Type: text/x-test';
     $result = $request->headers();
     $message = "Expected value `{$expected}` not found in result.";
     $this->assertTrue(in_array($expected, $result), $message);
     $expected = '#Content-Type: text/x-test#';
     $result = $request->to('string');
     $this->assertPattern($expected, $result);
 }
Пример #3
0
 /**
  * Expands on `\net\http\Message::headers()` by translating field names and values to those
  * provided by the server environment.
  *
  * @param string $key
  * @param string $value
  * @param boolean $replace
  * @return mixed
  */
 public function headers($key = null, $value = null, $replace = true)
 {
     if (is_string($key) && !isset($this->headers[$key]) && $value === null) {
         $env = strtoupper(str_replace('-', '_', $key));
         if (!in_array($env, array('CONTENT_TYPE', 'CONTENT_LENGTH'))) {
             $env = 'HTTP_' . $env;
         }
         if (!empty($this->_env[$env])) {
             $this->headers($key, $this->_env[$env]);
             return $this->_env[$env];
         }
     }
     if (!$key) {
         foreach ($this->_env as $name => $value) {
             if (substr($name, 0, 5) == 'HTTP_') {
                 $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
                 $this->headers($name, $value);
             }
         }
         $this->headers('Content-Type');
         $this->headers('Content-Length');
     }
     return parent::headers($key, $value, $replace);
 }
Пример #4
0
 public function testDigest()
 {
     $request = new Request(array('path' => 'http_auth', 'auth' => array('realm' => 'app', 'qop' => 'auth', 'nonce' => '4bca0fbca7bd0', 'opaque' => 'd3fb67a7aa4d887ec4bf83040a820a46'), 'username' => 'gwoo', 'password' => 'li3'));
     $cnonce = md5(time());
     $user = md5("gwoo:app:li3");
     $nonce = "4bca0fbca7bd0:00000001:{$cnonce}:auth";
     $req = md5("GET:/http_auth");
     $hash = md5("{$user}:{$nonce}:{$req}");
     $request->to('url');
     preg_match('/response="(.*?)"/', $request->headers('Authorization'), $matches);
     list($match, $response) = $matches;
     $expected = $hash;
     $result = $response;
     $this->assertEqual($expected, $result);
 }