mirror of
https://github.com/seejohnrun/haste-server.git
synced 2024-12-24 11:06:59 +00:00
Cancellation should only last as long as the handler
This commit is contained in:
parent
71c791c113
commit
8c2add94a2
1 changed files with 3 additions and 2 deletions
|
@ -49,20 +49,21 @@ DocumentHandler.prototype.handleRawGet = function(key, response, skipExpire) {
|
|||
DocumentHandler.prototype.handlePost = function(request, response) {
|
||||
var _this = this;
|
||||
var buffer = '';
|
||||
var cancelled = false;
|
||||
request.on('data', function(data) {
|
||||
if (!buffer) {
|
||||
response.writeHead(200, { 'content-type': 'application/json' });
|
||||
}
|
||||
buffer += data.toString();
|
||||
if (_this.maxLength && buffer.length > _this.maxLength) {
|
||||
_this.cancelled = true;
|
||||
cancelled = true;
|
||||
winston.warn('document >maxLength', { maxLength: _this.maxLength });
|
||||
response.writeHead(400, { 'content-type': 'application/json' });
|
||||
response.end(JSON.stringify({ message: 'Document exceeds maximum length.' }));
|
||||
}
|
||||
});
|
||||
request.on('end', function(end) {
|
||||
if (_this.cancelled) return;
|
||||
if (cancelled) return;
|
||||
_this.chooseKey(function(key) {
|
||||
_this.store.set(key, buffer, function(res) {
|
||||
if (res) {
|
||||
|
|
Loading…
Reference in a new issue