Send headers when making a request.

Add headerLines property to Message
Remove invalid default value for protocol in Response
This commit is contained in:
PJ Dietz 2013-01-28 15:53:18 -05:00
parent 0bae1c1b48
commit 1bad8e35a0
3 changed files with 19 additions and 7 deletions

View File

@ -62,6 +62,8 @@ abstract class Message
return $this->getBody();
case 'headers':
return $this->getHeaders();
case 'headerLines':
return $this->getHeaderLines();
case 'protocol':
return $this->getProtocol();
case 'protocolVersion':
@ -123,6 +125,20 @@ abstract class Message
return $this->headers;
}
/**
* Return an array containing one string for each header as "field: value"
*
* @return string
*/
public function getHeaderLines()
{
$lines = array();
foreach ($this->headers as $field => $value) {
$lines[] = sprintf('%s: %s', $field, $value);
}
return $lines;
}
/**
* Return the value of a given header, or false if it does not exist.
*

View File

@ -299,6 +299,9 @@ class Request extends Message
}
// Add headers.
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headerLines);
// Make the cURL request.
$result = curl_exec($ch);

View File

@ -59,13 +59,6 @@ class Response extends Message
if (!is_null($body)) {
$this->body = $body;
}
if (isset($_SERVER['SERVER_PROTOCOL'])) {
$this->protocol = $_SERVER['SERVER_PROTOCOL'];
} else {
$this->protocol = 'HTTP/1.1';
}
}
// -------------------------------------------------------------------------