diff --git a/lib/server/commands/Put.js b/lib/server/commands/Put.js index 266fe9fc..153a24b9 100644 --- a/lib/server/commands/Put.js +++ b/lib/server/commands/Put.js @@ -138,83 +138,59 @@ unchunkedMethod.chunked = function (arg, callback) { return; } arg.checkIfHeader(r, function () { - if (arg.contentLength === 0) { - if (r) { - arg.requirePrivilege(targetSource ? ['canSource', 'canWrite'] : ['canWrite'], r, function () { - r.write(targetSource, function (e, stream) { return process.nextTick(function () { - if (stream) - stream.end(); - if (e) - arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); - else { - arg.invokeEvent('write', r); - arg.setCode(WebDAVRequest_1.HTTPCodes.OK); - } - callback(); - }); }); - }); - return; - } + if (e) { createResource(arg, callback, function (r) { - arg.setCode(WebDAVRequest_1.HTTPCodes.Created); - callback(); - }); - } - else { - if (e) { - createResource(arg, callback, function (r) { - r.write(targetSource, function (e, stream) { return process.nextTick(function () { - if (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); - callback(); - return; - } - arg.request.pipe(stream); - stream.on('finish', function (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.Created); - arg.invokeEvent('write', r); - callback(); - }); - stream.on('error', function (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); - callback(); - }); - }); }); - }); - return; - } - arg.requirePrivilege(targetSource ? ['canSource', 'canWrite'] : ['canWrite'], r, function () { - r.type(function (e, type) { return process.nextTick(function () { + r.write(targetSource, function (e, stream) { return process.nextTick(function () { if (e) { arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); callback(); return; } - if (!type.isFile) { - arg.setCode(WebDAVRequest_1.HTTPCodes.MethodNotAllowed); + arg.request.pipe(stream); + stream.on('finish', function (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.Created); + arg.invokeEvent('write', r); callback(); - return; - } - r.write(targetSource, function (e, stream) { return process.nextTick(function () { - if (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); - callback(); - return; - } - arg.request.pipe(stream); - stream.on('finish', function (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.OK); - arg.invokeEvent('write', r); - callback(); - }); - stream.on('error', function (e) { - arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); - callback(); - }); - }); }); + }); + stream.on('error', function (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); + callback(); + }); }); }); }); + return; } + arg.requirePrivilege(targetSource ? ['canSource', 'canWrite'] : ['canWrite'], r, function () { + r.type(function (e, type) { return process.nextTick(function () { + if (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); + callback(); + return; + } + if (!type.isFile) { + arg.setCode(WebDAVRequest_1.HTTPCodes.MethodNotAllowed); + callback(); + return; + } + r.write(targetSource, function (e, stream) { return process.nextTick(function () { + if (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); + callback(); + return; + } + arg.request.pipe(stream); + stream.on('finish', function (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.OK); + arg.invokeEvent('write', r); + callback(); + }); + stream.on('error', function (e) { + arg.setCode(WebDAVRequest_1.HTTPCodes.InternalServerError); + callback(); + }); + }); }); + }); }); + }); }); }); }; diff --git a/lib/server/webDAVServer/StartStop.js b/lib/server/webDAVServer/StartStop.js index f3a9afdb..0853bb22 100644 --- a/lib/server/webDAVServer/StartStop.js +++ b/lib/server/webDAVServer/StartStop.js @@ -120,7 +120,7 @@ function start(port, callback) { base.response.end(); _this.invokeAfterRequest(base, null); }; - if (!_this.options.canChunk || !method.chunked || base.contentLength <= 0) { + if (!_this.options.canChunk || !method.chunked) { var go_1 = function () { _this.invokeBeforeRequest(base, function () { method(base, base.exit); diff --git a/src/server/commands/Put.ts b/src/server/commands/Put.ts index 8b662acb..aa4799e9 100644 --- a/src/server/commands/Put.ts +++ b/src/server/commands/Put.ts @@ -172,98 +172,68 @@ export default function unchunkedMethod(arg : MethodCallArgs, callback) } arg.checkIfHeader(r, () => { - if(arg.contentLength === 0) - { // Create file - if(r) - { // Resource exists => empty it - arg.requirePrivilege(targetSource ? [ 'canSource', 'canWrite' ] : [ 'canWrite' ], r, () => { - r.write(targetSource, (e, stream) => process.nextTick(() => { - if(stream) - stream.end(); - - if(e) - arg.setCode(HTTPCodes.InternalServerError) - else - { - arg.invokeEvent('write', r); - arg.setCode(HTTPCodes.OK) - } - callback() - })) - }) - return; - } - + if(e) + { // Resource not found createResource(arg, callback, (r) => { - arg.setCode(HTTPCodes.Created) - callback(); - }) - } - else - { // Write to a file - if(e) - { // Resource not found - createResource(arg, callback, (r) => { - r.write(targetSource, (e, stream) => process.nextTick(() => { - if(e) - { - arg.setCode(HTTPCodes.InternalServerError); - callback(); - return; - } - - arg.request.pipe(stream); - stream.on('finish', (e) => { - arg.setCode(HTTPCodes.Created) - arg.invokeEvent('write', r); - callback(); - }); - stream.on('error', (e) => { - arg.setCode(HTTPCodes.InternalServerError) - callback(); - }); - })) - }) - return; - } - - arg.requirePrivilege(targetSource ? [ 'canSource', 'canWrite' ] : [ 'canWrite' ], r, () => { - r.type((e, type) => process.nextTick(() => { + r.write(targetSource, (e, stream) => process.nextTick(() => { if(e) { arg.setCode(HTTPCodes.InternalServerError); callback(); return; } - if(!type.isFile) + + arg.request.pipe(stream); + stream.on('finish', (e) => { + arg.setCode(HTTPCodes.Created) + arg.invokeEvent('write', r); + callback(); + }); + stream.on('error', (e) => { + arg.setCode(HTTPCodes.InternalServerError) + callback(); + }); + })) + }) + return; + } + + arg.requirePrivilege(targetSource ? [ 'canSource', 'canWrite' ] : [ 'canWrite' ], r, () => { + r.type((e, type) => process.nextTick(() => { + if(e) + { + arg.setCode(HTTPCodes.InternalServerError); + callback(); + return; + } + if(!type.isFile) + { + arg.setCode(HTTPCodes.MethodNotAllowed); + callback(); + return; + } + + r.write(targetSource, (e, stream) => process.nextTick(() => { + if(e) { - arg.setCode(HTTPCodes.MethodNotAllowed); + arg.setCode(HTTPCodes.InternalServerError); callback(); return; } - r.write(targetSource, (e, stream) => process.nextTick(() => { - if(e) - { - arg.setCode(HTTPCodes.InternalServerError); - callback(); - return; - } - - arg.request.pipe(stream); - stream.on('finish', (e) => { - arg.setCode(HTTPCodes.OK) - arg.invokeEvent('write', r); - callback(); - }); - stream.on('error', (e) => { - arg.setCode(HTTPCodes.InternalServerError) - callback(); - }); - })) + arg.request.pipe(stream); + stream.on('finish', (e) => { + arg.setCode(HTTPCodes.OK) + arg.invokeEvent('write', r); + callback(); + }); + stream.on('error', (e) => { + arg.setCode(HTTPCodes.InternalServerError) + callback(); + }); })) - }) - } + })) + }) }) }) } diff --git a/src/server/webDAVServer/StartStop.ts b/src/server/webDAVServer/StartStop.ts index edbc7bbf..12dd56a6 100644 --- a/src/server/webDAVServer/StartStop.ts +++ b/src/server/webDAVServer/StartStop.ts @@ -151,7 +151,7 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We this.invokeAfterRequest(base, null); }; - if(!this.options.canChunk || !method.chunked || base.contentLength <= 0) + if(!this.options.canChunk || !method.chunked) { const go = () => {