Merge pull request #530 from CartoDB/copy-gunzip-exceptions
Handle gunzip/zlib errors
This commit is contained in:
commit
911a9efe1b
3
NEWS.md
3
NEWS.md
@ -3,7 +3,8 @@
|
||||
## 2.2.1
|
||||
Released 2018-mm-dd
|
||||
|
||||
Announcements:
|
||||
Bug fixes:
|
||||
* Errors from zlib while gunzipping (`/sql/copyfrom` compressed requests) are now handled correctly.
|
||||
|
||||
|
||||
## 2.2.0
|
||||
|
@ -125,6 +125,11 @@ function handleCopyFrom (logger) {
|
||||
pgstream.emit('error', err);
|
||||
})
|
||||
.pipe(isGzip ? zlib.createGunzip() : new PassThrough())
|
||||
.on('error', err => {
|
||||
err.message = `Error while gunzipping: ${err.message}`;
|
||||
metrics.end(null, err);
|
||||
pgstream.emit('error', err);
|
||||
})
|
||||
.on('data', data => {
|
||||
metrics.addSize(data.length);
|
||||
|
||||
|
@ -187,6 +187,28 @@ describe('copy-endpoints', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error when gzip headers are not correct', function(done) {
|
||||
assert.response(server, {
|
||||
url: "/api/v1/sql/copyfrom?" + querystring.stringify({
|
||||
q: "COPY copy_endpoints_test (id, name) FROM STDIN WITH (FORMAT CSV, DELIMITER ',', HEADER true)"
|
||||
}),
|
||||
data: fs.createReadStream(__dirname + '/../support/csv/copy_test_table.csv'),
|
||||
headers: {
|
||||
host: 'vizzuality.cartodb.com',
|
||||
'content-encoding': 'gzip'
|
||||
},
|
||||
method: 'POST'
|
||||
},{}, function(err, res) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(
|
||||
JSON.parse(res.body),
|
||||
{
|
||||
error:["Error while gunzipping: incorrect header check"]
|
||||
}
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user