Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Httpful/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* itself very nicely to "chaining". You will see several "alias"
* methods: more readable method definitions that wrap
* their more concise counterparts. You will also notice
* no public constructor. This two adds to the readability
* no public constructor. This too adds to the readability
* and "chainabilty" of the library.
*
* @author Nate Good <me@nategood.com>
Expand Down Expand Up @@ -760,7 +760,7 @@ private static function _initializeDefaults()
// recusion. Do not use this syntax elsewhere.
// It goes against the whole readability
// and transparency idea.
self::$_template = new Request(array('method' => Http::GET));
self::$_template = new static(array('method' => Http::GET));

// This is more like it...
self::$_template
Expand Down Expand Up @@ -811,7 +811,7 @@ public static function init($method = null, $mime = null)
if (!isset(self::$_template))
self::_initializeDefaults();

$request = new Request();
$request = new static();
return $request
->_setDefaults()
->method($method)
Expand Down
19 changes: 1 addition & 18 deletions src/Httpful/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,24 +115,7 @@ public function _parse($body)
*/
public function _parseHeaders($headers)
{
$headers = preg_split("/(\r|\n)+/", $headers, -1, \PREG_SPLIT_NO_EMPTY);
$parse_headers = array();
for ($i = 1; $i < count($headers); $i++) {
list($key, $raw_value) = explode(':', $headers[$i], 2);
$key = trim($key);
$value = trim($raw_value);
if (array_key_exists($key, $parse_headers)) {
// See HTTP RFC Sec 4.2 Paragraph 5
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
// If a header appears more than once, it must also be able to
// be represented as a single header with a comma-separated
// list of values. We transform accordingly.
$parse_headers[$key] .= ',' . $value;
} else {
$parse_headers[$key] = $value;
}
}
return $parse_headers;
return Response\Headers::fromString($headers)->toArray();
}

public function _parseCode($headers)
Expand Down
32 changes: 21 additions & 11 deletions src/Httpful/Response/Headers.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ private function __construct($headers)
*/
public static function fromString($string)
{
$lines = preg_split("/(\r|\n)+/", $string, -1, PREG_SPLIT_NO_EMPTY);
array_shift($lines); // HTTP HEADER
$headers = array();
foreach ($lines as $line) {
list($name, $value) = explode(':', $line, 2);
$headers[strtolower(trim($name))] = trim($value);
$headers = preg_split("/(\r|\n)+/", $string, -1, \PREG_SPLIT_NO_EMPTY);
$parse_headers = array();
for ($i = 1; $i < count($headers); $i++) {
list($key, $raw_value) = explode(':', $headers[$i], 2);
$key = trim($key);
$value = trim($raw_value);
if (array_key_exists($key, $parse_headers)) {
// See HTTP RFC Sec 4.2 Paragraph 5
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
// If a header appears more than once, it must also be able to
// be represented as a single header with a comma-separated
// list of values. We transform accordingly.
$parse_headers[$key] .= ',' . $value;
} else {
$parse_headers[$key] = $value;
}
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would be a breaking change. It's one I'm for but I believe we'll need to wait to do this until the next major release.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's been three years since the last mayor release, and about one year since the last release. I think it's time for some breaking changes :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong feelings about this one, one way or another.

return new self($headers);
return new self($parse_headers);
}

/**
Expand All @@ -36,7 +46,7 @@ public static function fromString($string)
*/
public function offsetExists($offset)
{
return isset($this->headers[strtolower($offset)]);
return isset($this->headers[$offset]);
}

/**
Expand All @@ -45,8 +55,8 @@ public function offsetExists($offset)
*/
public function offsetGet($offset)
{
if (isset($this->headers[$name = strtolower($offset)])) {
return $this->headers[$name];
if (isset($this->headers[$offset])) {
return $this->headers[$offset];
}
}

Expand Down Expand Up @@ -85,4 +95,4 @@ public function toArray()
return $this->headers;
}

}
}