Exemple #1
0
 /**
  * Adds a header to the collection, either in "Header: Value" format
  * or an {@link Ergo_Http_HeaderField} object.
  * @chainable
  */
 function add($header)
 {
     // convert to object form
     if (is_string($header)) {
         $header = Ergo_Http_HeaderField::fromString($header);
     }
     $this->_headers[] = $header;
     return $this;
 }
Exemple #2
0
 /**
  * Parses a response into headers and a body
  */
 private function _buildResponse($response)
 {
     $sections = explode("\r\n\r\n", $response, 2);
     $body = isset($sections[1]) ? $sections[1] : NULL;
     $headers = array();
     $headerlines = explode("\n", $sections[0]);
     // process status
     list($http, $code, $message) = explode(' ', $headerlines[0], 3);
     // process headers
     foreach (array_slice($headerlines, 1) as $headerline) {
         $headers[] = Ergo_Http_HeaderField::fromString($headerline);
     }
     $response = new Ergo_Http_Response($code, $headers, $body);
     // pass the response through the filter chain
     foreach ($this->_filters as $filter) {
         $response = $filter->response($response);
     }
     return $response;
 }
Exemple #3
0
 public function testRoundTrip()
 {
     $string = "Test: blarg: meh\r\n";
     $this->assertEqual(Ergo_Http_HeaderField::fromString($string)->__toString(), $string);
 }