Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Telling the server we want HTTP/1.1, no longer sending Connection: Ke…
Browse files Browse the repository at this point in the history
…ep-Alive, not connection pooling on Connection: close, and better !$line checking.
  • Loading branch information
sbisbee committed Aug 11, 2011
1 parent be94f0c commit 5bf9a69
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Sag.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,6 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
// Build the request packet.
$headers["Host"] = "{$this->host}:{$this->port}";
$headers["User-Agent"] = "Sag/0.6";
$headers["Connection"] = "Keep-Alive";

/*
* This prevents some unRESTful requests, such as inline attachments in
Expand Down Expand Up @@ -942,7 +941,8 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
$headers['Content-Length'] = strlen($data);
}

$buff = "$method $url HTTP/1.0\r\n";
$buff = "$method $url HTTP/1.1\r\n";

foreach($headers as $k => $v) {
$buff .= "$k: $v\r\n";
}
Expand Down Expand Up @@ -1008,7 +1008,6 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
$response->body = '';

$isHeader = true;
$sockInfo = stream_get_meta_data($sock);

// Read in the response.
while(
Expand All @@ -1028,13 +1027,15 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
)
)
) {
$sockInfo = stream_get_meta_data($sock);

if($sockInfo['timed_out']) {
throw new SagException('Connection timed out while reading.');
}

$line = fgets($sock);

if(!$line && !feof($sock)) {
if(!$line && !$sockInfo['feof'] && !$sockInfo['timed_out']) {
throw new SagException('Unexpectedly failed to retrieve a line from the socket before the end of the file.');
}

Expand Down Expand Up @@ -1078,8 +1079,8 @@ private function procPacket($method, $url, $data = null, $headers = array()) {
}
}

//We're done with the socket, so someone else can use it.
if($response->headers->Connection == 'Keep-Alive') {
// HTTP/1.1 assumes persisted connections, but proxies might close them.
if(strtolower($response->headers->Connection) != 'close') {
$this->connPool[] = $sock;
}

Expand Down

0 comments on commit 5bf9a69

Please sign in to comment.