From 2cec9811e2f9adc966dfb9f276ea195ef0c7a22d Mon Sep 17 00:00:00 2001 From: adrien Date: Mon, 22 Jan 2018 08:04:32 +0100 Subject: [PATCH] Fixed the OPTIONS result ('Allow' header) on the root element --- lib/server/v2/RequestContext.js | 22 +++++++++++----------- src/server/v2/RequestContext.ts | 30 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/lib/server/v2/RequestContext.js b/lib/server/v2/RequestContext.js index 08e2c747..f8fa8244 100644 --- a/lib/server/v2/RequestContext.js +++ b/lib/server/v2/RequestContext.js @@ -167,6 +167,16 @@ var HTTPRequestContext = (function (_super) { response.setHeader('Access-Control-Allow-Credentials', 'true'); response.setHeader('Access-Control-Expose-Headers', 'DAV, content-length, Allow'); response.setHeader('Server', server.options.serverName + '/' + server.options.version); + var setAllowHeader = function (type) { + var allowedMethods = []; + for (var name_3 in server.methods) { + var method = server.methods[name_3]; + if (!method.isValidFor || method.isValidFor(ctx, type)) + allowedMethods.push(name_3.toUpperCase()); + } + response.setHeader('Allow', allowedMethods.join(',')); + callback(null, ctx); + }; ctx.askForAuthentication(false, function (e) { if (e) { callback(e, ctx); @@ -181,7 +191,7 @@ var HTTPRequestContext = (function (_super) { if (server.options.requireAuthentification && (!user || user.isDefaultUser || e === Errors_1.Errors.UserNotFound)) return callback(Errors_1.Errors.MissingAuthorisationHeader, ctx); server.getFileSystem(ctx.requested.path, function (fs, _, subPath) { - fs.type(ctx, subPath, function (e, type) { + fs.type(ctx.requested.path.isRoot() ? server.createExternalContext() : ctx, subPath, function (e, type) { if (e) type = undefined; setAllowHeader(type); @@ -189,16 +199,6 @@ var HTTPRequestContext = (function (_super) { }); }); }); - function setAllowHeader(type) { - var allowedMethods = []; - for (var name_3 in server.methods) { - var method = server.methods[name_3]; - if (!method.isValidFor || method.isValidFor(ctx, type)) - allowedMethods.push(name_3.toUpperCase()); - } - response.setHeader('Allow', allowedMethods.join(',')); - callback(null, ctx); - } }; HTTPRequestContext.encodeURL = function (url) { return encodeURI(url); diff --git a/src/server/v2/RequestContext.ts b/src/server/v2/RequestContext.ts index 62a88209..d389ff6b 100644 --- a/src/server/v2/RequestContext.ts +++ b/src/server/v2/RequestContext.ts @@ -236,6 +236,20 @@ export class HTTPRequestContext extends RequestContext response.setHeader('Access-Control-Allow-Credentials', 'true'); response.setHeader('Access-Control-Expose-Headers', 'DAV, content-length, Allow'); response.setHeader('Server', server.options.serverName + '/' + server.options.version); + + const setAllowHeader = (type ?: ResourceType) => + { + const allowedMethods = []; + for(const name in server.methods) + { + const method = server.methods[name]; + if(!method.isValidFor || method.isValidFor(ctx, type)) + allowedMethods.push(name.toUpperCase()); + } + + response.setHeader('Allow', allowedMethods.join(',')); + callback(null, ctx); + }; ctx.askForAuthentication(false, (e) => { if(e) @@ -256,7 +270,7 @@ export class HTTPRequestContext extends RequestContext return callback(Errors.MissingAuthorisationHeader, ctx); server.getFileSystem(ctx.requested.path, (fs, _, subPath) => { - fs.type(ctx, subPath, (e, type) => { + fs.type(ctx.requested.path.isRoot() ? server.createExternalContext() : ctx, subPath, (e, type) => { if(e) type = undefined; @@ -265,20 +279,6 @@ export class HTTPRequestContext extends RequestContext }) }) }) - - function setAllowHeader(type ?: ResourceType) - { - const allowedMethods = []; - for(const name in server.methods) - { - const method = server.methods[name]; - if(!method.isValidFor || method.isValidFor(ctx, type)) - allowedMethods.push(name.toUpperCase()); - } - - response.setHeader('Allow', allowedMethods.join(',')); - callback(null, ctx); - } } static encodeURL(url : string)