Skip to content

Commit

Permalink
修复propfind depth问题
Browse files Browse the repository at this point in the history
  • Loading branch information
masx200 committed Sep 2, 2020
1 parent 9a2c4bb commit efc5e5f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
10 changes: 10 additions & 0 deletions dist/webdav-cli.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ class WebdavCli {
console.log({ method, url }, headers);
next();
});
server.beforeRequest((arg, next) => {
const { headers, method } = arg.request;
const { depth } = headers;
if (method === 'PROPFIND' && depth !== '0' && depth !== '1') {
arg.setCode(403);
arg.exit();
} else {
next();
}
});
server.afterRequest((arg, next) => {
const log = `>> ${arg.request.method} ${arg.requested.uri} > ${arg.response.statusCode} ${arg.response.statusMessage}`;
console.log(log);
Expand Down
8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"registry": "https://registry.npmjs.com"
},
"name": "@masx200/webdav-cli",
"version": "2.0.0",
"version": "2.0.1",
"description": "A simple zero-configuration command-line webdav server",
"license": "MIT",
"keywords": [
Expand All @@ -13,12 +13,6 @@
"webdav",
"server"
],
"files": [
"dist",
"certs",
"index.js",
"index.d.ts"
],
"bin": {
"webdav-cli": "dist/webdav-cli.cli.js"
},
Expand Down
11 changes: 10 additions & 1 deletion src/webdav-cli.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,16 @@ export class WebdavCli {
console.log({ method, url }, headers);
next();
});

server.beforeRequest((arg, next) => {
const { headers, method } = arg.request;
const { depth } = headers;
if (method === 'PROPFIND' && depth !== '0' && depth !== '1') {
arg.setCode(403);
arg.exit();
} else {
next();
}
});
server.afterRequest((arg, next) => {
const log = `>> ${arg.request.method} ${arg.requested.uri} > ${arg.response.statusCode} ${arg.response.statusMessage}`;
// server.emit('log', null, null, '/', log);
Expand Down

0 comments on commit efc5e5f

Please sign in to comment.