Skip to content

Commit b08d2d8

Browse files
author
francois
committed
[wiki:sfWebBrowserPlugin] Fixed a few limit case bugs and made the tests pass
git-svn-id: http://svn.symfony-project.com/plugins/sfWebBrowserPlugin/trunk@18167 ee427ae8-e902-0410-961c-c3ed070cd9f9
1 parent e611b43 commit b08d2d8

File tree

4 files changed

+289
-149
lines changed

4 files changed

+289
-149
lines changed

lib/sfFopenAdapter.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct($options = array())
4141
*/
4242
public function call($browser, $uri, $method = 'GET', $parameters = array(), $headers = array())
4343
{
44-
$m_headers = array_merge($browser->getDefaultRequestHeaders(), $browser->initializeRequestHeaders($headers));
44+
$m_headers = array_merge(array('Content-Type' => 'application/x-www-form-urlencoded'), $browser->getDefaultRequestHeaders(), $browser->initializeRequestHeaders($headers));
4545
$request_headers = $browser->prepareHeaders($m_headers);
4646

4747
// Read the response from the server

lib/sfSocketsAdapter.class.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct($options = array())
4141
*/
4242
public function call($browser, $uri, $method = 'GET', $parameters = array(), $headers = array())
4343
{
44-
$m_headers = array_merge($browser->getDefaultRequestHeaders(), $browser->initializeRequestHeaders($headers));
44+
$m_headers = array_merge(array('Content-Type' => 'application/x-www-form-urlencoded'), $browser->getDefaultRequestHeaders(), $browser->initializeRequestHeaders($headers));
4545
$request_headers = $browser->prepareHeaders($m_headers);
4646

4747
$url_info = parse_url($uri);
@@ -62,14 +62,7 @@ public function call($browser, $uri, $method = 'GET', $parameters = array(), $he
6262
$request .= $request_headers;
6363
$request .= "Connection: Close\r\n";
6464

65-
if ($method == 'POST')
66-
{
67-
$request .= 'Content-Length: '.strlen($body)."\r\n";
68-
$request .= "Content-type: application/x-www-form-urlencoded\r\n";
69-
$request .= "\r\n";
70-
$request .= http_build_query($parameters, '', '&');
71-
}
72-
else if ($method == 'PUT')
65+
if ($method == 'PUT' && is_array($parameters) && array_key_exists('file', $parameters))
7366
{
7467
$fp = fopen($parameters['file'], 'rb');
7568
$sent = 0;
@@ -90,8 +83,15 @@ public function call($browser, $uri, $method = 'GET', $parameters = array(), $he
9083
}
9184
fclose($fp);
9285
}
86+
elseif ($method == 'POST' || $method == 'PUT')
87+
{
88+
$body = is_array($parameters) ? http_build_query($parameters, '', '&') : $parameters;
89+
$request .= 'Content-Length: '.strlen($body)."\r\n";
90+
$request .= "\r\n";
91+
$request .= $body;
92+
}
9393

94-
$request = "\r\n";
94+
$request .= "\r\n";
9595

9696
fwrite($socket, $request);
9797

@@ -110,6 +110,7 @@ public function call($browser, $uri, $method = 'GET', $parameters = array(), $he
110110
$status_line = array_shift($response_lines);
111111

112112
$start_body = false;
113+
$response_headers = array();
113114
for($i=0; $i<count($response_lines); $i++)
114115
{
115116
// grab body
@@ -134,12 +135,15 @@ public function call($browser, $uri, $method = 'GET', $parameters = array(), $he
134135
$response_headers[] = $response_lines[$i];
135136
}
136137
}
137-
138+
139+
$browser->setResponseHeaders($response_headers);
140+
138141
// grab status code
139142
preg_match('@(\d{3})@', $status_line, $status_code);
140-
141-
$browser->setResponseHeaders($response_headers);
142-
$browser->setResponseCode($status_code[1]);
143+
if(isset($status_code[1]))
144+
{
145+
$browser->setResponseCode($status_code[1]);
146+
}
143147
$browser->setResponseText(trim($response_body));
144148

145149
return $browser;

lib/sfWebBrowser.class.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,15 @@ public function setResponseHeaders($headers = array())
556556
*/
557557
public function setResponseCode($firstLine)
558558
{
559-
preg_match('/\d{3}/', $firstLine, $matches);
560-
$this->responseCode = $matches[0];
559+
preg_match('/\d{3}/', $firstLine, $matches);
560+
if(isset($matches[0]))
561+
{
562+
$this->responseCode = $matches[0];
563+
}
564+
else
565+
{
566+
$this->responseCode = '';
567+
}
561568

562569
return $this;
563570
}
@@ -614,7 +621,7 @@ public function getResponseBody()
614621
{
615622
preg_match('/<body.*?>(.*)<\/body>/si', $this->getResponseText(), $matches);
616623

617-
return $matches[1];
624+
return isset($matches[1]) ? $matches[1] : '';
618625
}
619626

620627
/**
@@ -793,11 +800,11 @@ public function initializeRequestHeaders($headers = array())
793800
{
794801
$encodings = explode(',', $headers['Accept-Encoding']);
795802
}
796-
if (function_exists('gzinflate'))
803+
if (function_exists('gzinflate') && !in_array('gzip', $encodings))
797804
{
798805
$encodings[] = 'gzip';
799806
}
800-
if (function_exists('gzuncompress'))
807+
if (function_exists('gzuncompress') && !in_array('deflate', $encodings))
801808
{
802809
$encodings[] = 'deflate';
803810
}

0 commit comments

Comments
 (0)