Exemple #1
0
 /**
  * {@inheritDoc}
  */
 public function normalize(array $headers)
 {
     $raw = [];
     foreach ($headers as $name => $value) {
         if (is_int($name)) {
             list($name, $value) = explode(":", $value, 2);
         }
         $name = Utils::normalizeHeaderName($name, $this->stripX);
         $value = trim($value);
         $raw[] = "{$name}: {$value}";
     }
     return $raw;
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function parse($headers, &$options = null)
 {
     $methods = HttpMethods::getValues();
     $methods = join("|", $methods);
     $regex = "~^({$methods})\\b~i";
     $parsed = [];
     $lines = preg_split("/\\R/", $headers);
     foreach ($lines as $line) {
         if (preg_match($regex, $line)) {
             $options = $line;
         } else {
             if (preg_match("~^HTTP/~", $line)) {
                 $options = $line;
             } else {
                 if (!empty($line)) {
                     list($name, $value) = preg_split("/:\\S*/", $line, 2);
                     $name = Utils::normalizeHeaderName($name);
                     $parsed[$name] = trim($value);
                 }
             }
         }
     }
     return $parsed;
 }
Exemple #3
0
 /**
  * Adds the data value to the curl request
  */
 protected function prepareData()
 {
     if (!empty($this->data)) {
         if ($this->method === HttpMethods::GET) {
             $this->url = Utils::appendUrlQuery($this->url, $this->data);
         } else {
             if ($this->method === HttpMethods::POST) {
                 curl_setopt($this->curl, CURLOPT_POSTFIELDS, $this->data);
             }
         }
     }
 }
Exemple #4
0
 /**
  * @covers Headzoo\Web\Tools\Utils::appendUrlQuery
  */
 public function testAppendUrlQuery()
 {
     $this->assertEquals("http://site.com?name=Sean&job=programmer", Utils::appendUrlQuery("http://site.com", "name=Sean&job=programmer"));
     $this->assertEquals("http://site.com?action=list&name=Sean&job=programmer", Utils::appendUrlQuery("http://site.com?action=list", "name=Sean&job=programmer"));
     $this->assertEquals("http://site.com?action=list&name=Sean&job=programmer", Utils::appendUrlQuery("http://site.com?action=list", "?name=Sean&job=programmer"));
 }