Skip to content

Commit

Permalink
Fixed the OPTIONS result ('Allow' header) on the root element
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jan 22, 2018
1 parent 7de911b commit 2cec981
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
22 changes: 11 additions & 11 deletions lib/server/v2/RequestContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -181,24 +191,14 @@ 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);
});
});
});
});
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);
Expand Down
30 changes: 15 additions & 15 deletions src/server/v2/RequestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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)
Expand Down

0 comments on commit 2cec981

Please sign in to comment.