Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit f9e2bec

Browse files
committed
Merge branch 'master' into develop
2 parents 1997093 + 911c017 commit f9e2bec

9 files changed

+80
-13
lines changed

lib/Doctrine/CouchDB/CouchDBClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static public function create(array $options)
121121
'ssl' => false,
122122
'path' => null,
123123
'logging' => false,
124-
'timeout' => 0.01,
124+
'timeout' => 10,
125125
);
126126
$options = array_merge($defaults, $options);
127127

lib/Doctrine/CouchDB/HTTP/AbstractHTTPClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class AbstractHTTPClient implements Client
2525
'port' => 5984,
2626
'ip' => '127.0.0.1',
2727
'ssl' => false,
28-
'timeout' => 0.01,
28+
'timeout' => 10,
2929
'keep-alive' => true,
3030
'username' => null,
3131
'password' => null,
@@ -47,7 +47,7 @@ abstract class AbstractHTTPClient implements Client
4747
* @param string $path
4848
* @return \Doctrine\CouchDB\HTTP\AbstractHTTPClient
4949
*/
50-
public function __construct($host = 'localhost', $port = 5984, $username = null, $password = null, $ip = null , $ssl = false, $path = null, $timeout = 0.01)
50+
public function __construct($host = 'localhost', $port = 5984, $username = null, $password = null, $ip = null , $ssl = false, $path = null, $timeout = 10)
5151
{
5252
$this->options['host'] = (string) $host;
5353
$this->options['port'] = (int) $port;

lib/Doctrine/CouchDB/HTTP/HTTPException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function fromResponse( $path, Response $response )
6666
}
6767

6868
return new self(
69-
"HTTP Error with status " . $response->status . " occoured while "
69+
"HTTP Error with status " . $response->status . " occurred while "
7070
. "requesting " . $path . ". Error: " . $response->body['error']
7171
. " " . $response->body['reason'],
7272
$response->status );

lib/Doctrine/CouchDB/HTTP/MultipartParserAndSender.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,11 @@ protected function parseAndSend($targetPath)
178178
{
179179
// Main response boundary of the multipart stream.
180180
$mainBoundary = trim($this->getNextLineFromSourceConnection());
181+
// If on the first line we have the size, then main boundary should be
182+
// on the second line.
183+
if (is_numeric($mainBoundary)) {
184+
$mainBoundary = trim($this->getNextLineFromSourceConnection());
185+
}
181186

182187
// Docs that don't have attachment.
183188
// These should be posted using Bulk upload.
@@ -194,7 +199,6 @@ protected function parseAndSend($targetPath)
194199

195200
} elseif (strpos($line, 'Content-Type') !== false) {
196201

197-
198202
list($header, $value) = explode(':', $line);
199203
$header = trim($header);
200204
$value = trim($value);

lib/Doctrine/CouchDB/HTTP/SocketClient.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ protected function buildRequest(
141141
array $headers = array()
142142
) {
143143
// Create basic request headers
144-
$host = "Host: {$this->options['host']}:{$this->options['port']}";
144+
$host = "Host: {$this->options['host']}";
145+
if ($this->options['port'] != 80) {
146+
$host .= ":{$this->options['port']}";
147+
}
145148
$request = "$method $path HTTP/1.1\r\n$host\r\n";
146149

147150
// Add basic auth if set

lib/Doctrine/CouchDB/HTTP/StreamClient.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ protected function checkConnection($method, $path, $data, $headers)
9292
}
9393
if ($this->httpFilePointer == null) {
9494
// TODO SSL support?
95+
$host = $this->options['host'];
96+
if ($this->options['port'] != 80) {
97+
$host .= ":{$this->options['port']}";
98+
}
9599
$this->httpFilePointer = @fopen(
96-
'http://' . $basicAuth . $this->options['host'] . ':' . $this->options['port'] . $path,
100+
'http://' . $basicAuth . $host . $path,
97101
'r',
98102
false,
99103
stream_context_create(

tests/Doctrine/Tests/CouchDB/CouchDBClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testCreateClientFromUrl()
3636
'username' => 'foo',
3737
'password' => 'bar',
3838
'ssl' => true,
39-
'timeout' => 0.01,
39+
'timeout' => 10,
4040
'keep-alive' => true,
4141
'path' => null,
4242
),
@@ -57,7 +57,7 @@ public function testCreateClientFromUrlWithPath()
5757
'username' => 'foo',
5858
'password' => 'bar',
5959
'ssl' => true,
60-
'timeout' => 0.01,
60+
'timeout' => 10,
6161
'keep-alive' => true,
6262
'path' => 'baz/qux',
6363
),

tests/Doctrine/Tests/CouchDB/Functional/CouchDBClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function testDropMultipleTimesSkips()
7474
public function testCreateDuplicateDatabaseThrowsException()
7575
{
7676
$this->couchClient->createDatabase($this->getTestDatabase());
77-
$this->setExpectedException('Doctrine\CouchDB\HTTP\HTTPException', 'HTTP Error with status 412 occoured while requesting /'.$this->getTestDatabase().'. Error: file_exists The database could not be created, the file already exists.');
77+
$this->setExpectedException('Doctrine\CouchDB\HTTP\HTTPException', 'HTTP Error with status 412 occurred while requesting /'.$this->getTestDatabase().'. Error: file_exists The database could not be created, the file already exists.');
7878
$this->couchClient->createDatabase($this->getTestDatabase());
7979
}
8080

@@ -87,7 +87,7 @@ public function testGetDatabaseInfo()
8787
$this->assertEquals($this->getTestDatabase(), $data['db_name']);
8888

8989
$notExistedDb = 'not_existed_db';
90-
$this->setExpectedException('Doctrine\CouchDB\HTTP\HTTPException','HTTP Error with status 404 occoured while requesting /'.$notExistedDb.'. Error: not_found no_db_file');
90+
$this->setExpectedException('Doctrine\CouchDB\HTTP\HTTPException','HTTP Error with status 404 occurred while requesting /'.$notExistedDb.'. Error: not_found no_db_file');
9191
$this->couchClient->getDatabaseInfo($notExistedDb);
9292
}
9393

@@ -670,7 +670,7 @@ public function test404WhenQueryAndNoDesignDocument()
670670

671671
$this->setExpectedException(
672672
'Doctrine\CouchDB\HTTP\HTTPException',
673-
'HTTP Error with status 404 occoured while requesting /doctrine_test_database/_design/foo/_view/not-found?. Error: not_found missing'
673+
'HTTP Error with status 404 occurred while requesting /doctrine_test_database/_design/foo/_view/not-found?. Error: not_found missing'
674674
);
675675

676676
$query->execute();

tests/Doctrine/Tests/CouchDB/Functional/HTTP/MultipartParserAndSenderTest.php

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,4 +319,60 @@ public function testRequestSuccessWithAttachments()
319319
$client->createDatabase($this->getTestDatabase());
320320
$client->deleteDatabase($copyDb);
321321
}
322-
}
322+
323+
/**
324+
* Test multipart request with body size in the request body.
325+
*/
326+
public function testMultipartRequestWithSize()
327+
{
328+
$this->streamClientMock->expects($this->once())
329+
->method('getStreamHeaders')
330+
->willReturn(array('status' => 200));
331+
$docs = array(
332+
'{"_id": "' . $this->docId . '","_rev": "1-abc","foo":"bar"}',
333+
'{"_id": "' . $this->docId . '","_rev": "1-abcd","foo":"baz"}',
334+
'{"_id": "' . $this->docId . '","_rev": "1-abcde","foo":"baz"}',
335+
);
336+
$string = <<<EOT
337+
--7b1596fc4940bc1be725ad67f11ec1c4
338+
Content-Type: application/json
339+
340+
$docs[0]
341+
--7b1596fc4940bc1be725ad67f11ec1c4
342+
Content-Type: application/json
343+
344+
$docs[1]
345+
--7b1596fc4940bc1be725ad67f11ec1c4
346+
Content-Type: application/json
347+
348+
$docs[2]
349+
--7b1596fc4940bc1be725ad67f11ec1c4
350+
EOT;
351+
$size = strlen($string);
352+
// Add the size.
353+
$string = <<<EOT
354+
$size
355+
$string
356+
EOT;
357+
358+
$stream = fopen('data://text/plain,' . $string,'r');
359+
$this->streamClientMock->expects($this->once())
360+
->method('getConnection')
361+
->willReturn($stream);
362+
363+
$response = $this->parserAndSender->request(
364+
$this->sourceMethod,
365+
$this->sourcePath,
366+
$this->targetPath,
367+
null,
368+
$this->sourceHeaders
369+
);
370+
// The returned response should have the JSON docs.
371+
$this->AssertEquals(2, count($response));
372+
$this->AssertEquals(3, count($response[0]));
373+
$this->AssertEquals($docs[0], $response[0][0]);
374+
$this->AssertEquals($docs[1], $response[0][1]);
375+
$this->AssertEquals($docs[2], $response[0][2]);
376+
}
377+
378+
}

0 commit comments

Comments
 (0)