Skip to content

Commit ee1155c

Browse files
committed
When no compression is enabled on the client, drivers SHOULD send an empty compression argument
1 parent 7aa7111 commit ee1155c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/main/php/com/mongodb/io/Connection.class.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ public function establish($options= [], $auth= null) {
9999
'driver' => ['name' => 'XP MongoDB Connectivity', 'version' => '3.0.0'],
100100
'os' => ['name' => php_uname('s'), 'type' => PHP_OS, 'architecture' => php_uname('m'), 'version' => php_uname('r')]
101101
],
102+
'compression' => ($param= ($options['params']['compressors'] ?? null))
103+
? explode(',', $param)
104+
: []
105+
,
102106
];
103107

104108
// If the optional field saslSupportedMechs is specified, the command also returns
@@ -112,10 +116,6 @@ public function establish($options= [], $auth= null) {
112116
$authSource= null;
113117
}
114118

115-
if ($compressors= ($options['params']['compressors'] ?? null)) {
116-
$params['compression']= explode(',', $compressors);
117-
}
118-
119119
try {
120120
$this->server= $this->hello($params);
121121
$this->compression= Compression::negotiate($this->server['compression'] ?? [], $options['params'] ?? []);

src/test/php/com/mongodb/unittest/ConnectionTest.class.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,21 @@ public function connect_handshake_populates_server_options() {
8686
Assert::equals(['$kind' => 'Standalone'] + $server, $c->server);
8787
}
8888

89+
#[Test, Values([[null, []], ['zlib', ['zlib']], ['zlib,zstd', ['zlib', 'zstd']]])]
90+
public function compressor_param_sent($compressors, $expected) {
91+
$socket= new TestingSocket($this->reply([
92+
'ok' => 1.0,
93+
'minWireVersion' => 0,
94+
'maxWireVersion' => 6,
95+
]));
96+
$c= new Connection($socket);
97+
$c->establish(['params' => ['compressors' => $compressors]]);
98+
99+
// Standard header (16 bytes) + admin.$cmd prologue (23 bytes)
100+
$offset= 39;
101+
Assert::equals($expected, $this->bson->document($socket->requests[0], $offset)['compression']);
102+
}
103+
89104
#[Test, Values([[[]], [['compression' => []]], [['compression' => ['unsupported']]]])]
90105
public function no_compression_negotiated($preference) {
91106
$c= new Connection(new TestingSocket($this->reply($preference + [

0 commit comments

Comments
 (0)