Send headers when making a request.
Add headerLines property to Message Remove invalid default value for protocol in Response
This commit is contained in:
parent
0bae1c1b48
commit
1bad8e35a0
|
|
@ -62,6 +62,8 @@ abstract class Message
|
||||||
return $this->getBody();
|
return $this->getBody();
|
||||||
case 'headers':
|
case 'headers':
|
||||||
return $this->getHeaders();
|
return $this->getHeaders();
|
||||||
|
case 'headerLines':
|
||||||
|
return $this->getHeaderLines();
|
||||||
case 'protocol':
|
case 'protocol':
|
||||||
return $this->getProtocol();
|
return $this->getProtocol();
|
||||||
case 'protocolVersion':
|
case 'protocolVersion':
|
||||||
|
|
@ -123,6 +125,20 @@ abstract class Message
|
||||||
return $this->headers;
|
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.
|
* Return the value of a given header, or false if it does not exist.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -299,6 +299,9 @@ class Request extends Message
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add headers.
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headerLines);
|
||||||
|
|
||||||
// Make the cURL request.
|
// Make the cURL request.
|
||||||
$result = curl_exec($ch);
|
$result = curl_exec($ch);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,13 +59,6 @@ class Response extends Message
|
||||||
if (!is_null($body)) {
|
if (!is_null($body)) {
|
||||||
$this->body = $body;
|
$this->body = $body;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_SERVER['SERVER_PROTOCOL'])) {
|
|
||||||
$this->protocol = $_SERVER['SERVER_PROTOCOL'];
|
|
||||||
} else {
|
|
||||||
$this->protocol = 'HTTP/1.1';
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------------------------------------------------------------
|
// -------------------------------------------------------------------------
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue