From faf858180fc6996a2ce24a9d1f4e3e084133ac2e Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Fri, 30 Jun 2017 14:51:57 +0200 Subject: [PATCH] Splitted the 'RequestContext' class into 'RequestContext', 'ExternalRequestContext' and 'HTTPRequestContext' --- lib/server/v2/RequestContext.d.ts | 43 +++--- lib/server/v2/RequestContext.js | 126 +++++++++------- lib/server/v2/WebDAVRequest.d.ts | 10 +- lib/server/v2/WebDAVRequest.js | 2 +- lib/server/v2/commands/Copy.d.ts | 6 +- lib/server/v2/commands/Copy.js | 2 +- lib/server/v2/commands/Delete.d.ts | 6 +- lib/server/v2/commands/Delete.js | 2 +- lib/server/v2/commands/Get.d.ts | 6 +- lib/server/v2/commands/Get.js | 2 +- lib/server/v2/commands/Head.d.ts | 6 +- lib/server/v2/commands/Head.js | 2 +- lib/server/v2/commands/Lock.d.ts | 4 +- lib/server/v2/commands/Mkcol.d.ts | 6 +- lib/server/v2/commands/Mkcol.js | 2 +- lib/server/v2/commands/Move.d.ts | 8 +- lib/server/v2/commands/Move.js | 2 +- lib/server/v2/commands/NotImplemented.d.ts | 4 +- lib/server/v2/commands/Options.d.ts | 4 +- lib/server/v2/commands/Propfind.d.ts | 6 +- lib/server/v2/commands/Propfind.js | 2 +- lib/server/v2/commands/Proppatch.d.ts | 6 +- lib/server/v2/commands/Proppatch.js | 2 +- lib/server/v2/commands/Put.d.ts | 6 +- lib/server/v2/commands/Put.js | 2 +- lib/server/v2/commands/Unlock.d.ts | 6 +- lib/server/v2/commands/Unlock.js | 2 +- lib/server/v2/webDAVServer/BeforeAfter.d.ts | 8 +- lib/server/v2/webDAVServer/StartStop.js | 2 +- lib/server/v2/webDAVServer/WebDAVServer.d.ts | 11 +- lib/server/v2/webDAVServer/WebDAVServer.js | 7 +- .../v2/authentication/HTTPAuthentication.d.ts | 4 +- .../HTTPBasicAuthentication.d.ts | 6 +- .../HTTPDigestAuthentication.d.ts | 4 +- lib/user/v2/simple/SimpleUserManager.d.ts | 2 +- src/server/v2/RequestContext.ts | 135 ++++++++++-------- src/server/v2/WebDAVRequest.ts | 10 +- src/server/v2/commands/Copy.ts | 6 +- src/server/v2/commands/Delete.ts | 6 +- src/server/v2/commands/Get.ts | 6 +- src/server/v2/commands/Head.ts | 6 +- src/server/v2/commands/Lock.ts | 10 +- src/server/v2/commands/Mkcol.ts | 6 +- src/server/v2/commands/Move.ts | 8 +- src/server/v2/commands/NotImplemented.ts | 4 +- src/server/v2/commands/Options.ts | 4 +- src/server/v2/commands/Propfind.ts | 10 +- src/server/v2/commands/Proppatch.ts | 6 +- src/server/v2/commands/Put.ts | 6 +- src/server/v2/commands/Unlock.ts | 6 +- src/server/v2/webDAVServer/BeforeAfter.ts | 10 +- src/server/v2/webDAVServer/Persistence.ts | 5 +- src/server/v2/webDAVServer/StartStop.ts | 4 +- src/server/v2/webDAVServer/Types.ts | 25 ---- src/server/v2/webDAVServer/WebDAVServer.ts | 21 ++- .../v2/authentication/HTTPAuthentication.ts | 4 +- .../authentication/HTTPBasicAuthentication.ts | 6 +- .../HTTPDigestAuthentication.ts | 4 +- src/user/v2/privilege/PrivilegeManager.ts | 4 - .../privilege/SimplePathPrivilegeManager.ts | 3 +- src/user/v2/simple/SimpleUserManager.ts | 2 +- 61 files changed, 337 insertions(+), 299 deletions(-) delete mode 100644 src/server/v2/webDAVServer/Types.ts diff --git a/lib/server/v2/RequestContext.d.ts b/lib/server/v2/RequestContext.d.ts index f46dddba..e6c52321 100644 --- a/lib/server/v2/RequestContext.d.ts +++ b/lib/server/v2/RequestContext.d.ts @@ -8,12 +8,16 @@ import { Path } from '../../manager/v2/Path'; import { IUser } from '../../user/v2/IUser'; import * as http from 'http'; export declare class RequestContextHeaders { - protected request: http.IncomingMessage; + protected headers: { + [name: string]: string; + }; contentLength: number; isSource: boolean; depth: number; host: string; - constructor(request: http.IncomingMessage); + constructor(headers: { + [name: string]: string; + }); find(name: string, defaultValue?: string): string; findBestAccept(defaultType?: string): string; } @@ -36,31 +40,38 @@ export declare class DefaultRequestContextExternalOptions implements RequestCont user: IUser; } export declare class RequestContext { + requested: RequestedResource; + headers: RequestContextHeaders; server: WebDAVServer; + user: IUser; + protected constructor(server: WebDAVServer, uri: string, headers: { + [name: string]: string; + }); + getResource(callback: ReturnCallback): any; + getResource(path: Path | string, callback: ReturnCallback): any; + getResourceSync(path?: Path | string): Resource; + fullUri(uri?: string): string; + prefixUri(): string; +} +export declare class ExternalRequestContext extends RequestContext { + static create(server: WebDAVServer): ExternalRequestContext; + static create(server: WebDAVServer, callback: (error: Error, ctx: ExternalRequestContext) => void): ExternalRequestContext; + static create(server: WebDAVServer, options: RequestContextExternalOptions): ExternalRequestContext; + static create(server: WebDAVServer, options: RequestContextExternalOptions, callback: (error: Error, ctx: ExternalRequestContext) => void): ExternalRequestContext; +} +export declare class HTTPRequestContext extends RequestContext { + responseBody: string; request: http.IncomingMessage; response: http.ServerResponse; exit: () => void; - responseBody: string; - requested: RequestedResource; - headers: RequestContextHeaders; - user: IUser; protected constructor(server: WebDAVServer, request: http.IncomingMessage, response: http.ServerResponse, exit: () => void); - static createExternal(server: WebDAVServer): RequestContext; - static createExternal(server: WebDAVServer, callback: (error: Error, ctx: RequestContext) => void): RequestContext; - static createExternal(server: WebDAVServer, options: RequestContextExternalOptions): RequestContext; - static createExternal(server: WebDAVServer, options: RequestContextExternalOptions, callback: (error: Error, ctx: RequestContext) => void): RequestContext; - static create(server: WebDAVServer, request: http.IncomingMessage, response: http.ServerResponse, callback: (error: Error, ctx: RequestContext) => void): void; + static create(server: WebDAVServer, request: http.IncomingMessage, response: http.ServerResponse, callback: (error: Error, ctx: HTTPRequestContext) => void): void; noBodyExpected(callback: () => void): void; checkIfHeader(resource: Resource, callback: () => void): any; checkIfHeader(fs: FileSystem, path: Path, callback: () => void): any; askForAuthentication(checkForUser: boolean, callback: (error: Error) => void): void; - getResource(callback: ReturnCallback): any; - getResource(path: Path | string, callback: ReturnCallback): any; - fullUri(uri?: string): string; - prefixUri(): string; writeBody(xmlObject: XMLElement | object): void; setCode(code: number, message?: string): void; static defaultStatusCode(error: Error): number; setCodeFromError(error: Error): boolean; } -export default RequestContext; diff --git a/lib/server/v2/RequestContext.js b/lib/server/v2/RequestContext.js index e2b676fa..5a256377 100644 --- a/lib/server/v2/RequestContext.js +++ b/lib/server/v2/RequestContext.js @@ -1,4 +1,14 @@ "use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); Object.defineProperty(exports, "__esModule", { value: true }); var XML_1 = require("../../helper/XML"); var IfParser_1 = require("../../helper/v2/IfParser"); @@ -8,8 +18,8 @@ var Errors_1 = require("../../Errors"); var http = require("http"); var url = require("url"); var RequestContextHeaders = (function () { - function RequestContextHeaders(request) { - this.request = request; + function RequestContextHeaders(headers) { + this.headers = headers; this.isSource = this.find('source', 'F').toUpperCase() === 'T' || this.find('translate', 'T').toUpperCase() === 'F'; this.host = this.find('Host', 'localhost'); var depth = this.find('Depth'); @@ -32,9 +42,9 @@ var RequestContextHeaders = (function () { RequestContextHeaders.prototype.find = function (name, defaultValue) { if (defaultValue === void 0) { defaultValue = null; } name = name.replace(/(-| )/g, '').toLowerCase(); - for (var k in this.request.headers) + for (var k in this.headers) if (k.replace(/(-| )/g, '').toLowerCase() === name) { - var value = this.request.headers[k].trim(); + var value = this.headers[k].trim(); if (value.length !== 0) return value; } @@ -76,20 +86,42 @@ var DefaultRequestContextExternalOptions = (function () { }()); exports.DefaultRequestContextExternalOptions = DefaultRequestContextExternalOptions; var RequestContext = (function () { - function RequestContext(server, request, response, exit) { + function RequestContext(server, uri, headers) { + this.headers = new RequestContextHeaders(headers); this.server = server; - this.request = request; - this.response = response; - this.exit = exit; - this.responseBody = undefined; - this.headers = new RequestContextHeaders(request); - var uri = url.parse(request.url).pathname; + uri = url.parse(uri).pathname; this.requested = { uri: uri, path: new Path_1.Path(uri) }; } - RequestContext.createExternal = function (server, _options, _callback) { + RequestContext.prototype.getResource = function (_path, _callback) { + var path = _callback ? new Path_1.Path(_path) : this.requested.path; + var callback = _callback ? _callback : _path; + this.server.getResource(this, path, callback); + }; + RequestContext.prototype.getResourceSync = function (path) { + path = path ? path : this.requested.path; + return this.server.getResourceSync(this, path); + }; + RequestContext.prototype.fullUri = function (uri) { + if (uri === void 0) { uri = null; } + if (!uri) + uri = this.requested.uri; + return (this.prefixUri() + uri).replace(/([^:])\/\//g, '$1/'); + }; + RequestContext.prototype.prefixUri = function () { + return 'http://' + this.headers.host.replace('/', ''); + }; + return RequestContext; +}()); +exports.RequestContext = RequestContext; +var ExternalRequestContext = (function (_super) { + __extends(ExternalRequestContext, _super); + function ExternalRequestContext() { + return _super !== null && _super.apply(this, arguments) || this; + } + ExternalRequestContext.create = function (server, _options, _callback) { var defaultValues = new DefaultRequestContextExternalOptions(); var options = _options && _options.constructor !== Function ? _options : defaultValues; var callback = _callback ? _callback : _options && _options.constructor === Function ? _options : function () { }; @@ -98,21 +130,28 @@ var RequestContext = (function () { if (options[name_2] === undefined) options[name_2] = defaultValues[name_2]; } - var ctx = new RequestContext(server, { - headers: options.headers, - url: options.url - }, null, null); - if (options.user) + var ctx = new ExternalRequestContext(server, options.url, options.headers); + if (options.user) { ctx.user = options.user; - else - server.httpAuthentication.getUser(ctx, function (e, user) { - ctx.user = options.user; - callback(e, ctx); - }); + process.nextTick(function () { return callback(null, ctx); }); + } return ctx; }; - RequestContext.create = function (server, request, response, callback) { - var ctx = new RequestContext(server, request, response, null); + return ExternalRequestContext; +}(RequestContext)); +exports.ExternalRequestContext = ExternalRequestContext; +var HTTPRequestContext = (function (_super) { + __extends(HTTPRequestContext, _super); + function HTTPRequestContext(server, request, response, exit) { + var _this = _super.call(this, server, request.url, request.headers) || this; + _this.responseBody = undefined; + _this.response = response; + _this.request = request; + _this.exit = exit; + return _this; + } + HTTPRequestContext.create = function (server, request, response, callback) { + var ctx = new HTTPRequestContext(server, request, response, null); response.setHeader('DAV', '1,2'); response.setHeader('Server', server.options.serverName + '/' + server.options.version); ctx.askForAuthentication(false, function (e) { @@ -141,14 +180,14 @@ var RequestContext = (function () { var allowedMethods = []; for (var name_3 in server.methods) { var method = server.methods[name_3]; - if (!method.isValidFor || method.isValidFor(type)) + if (!method.isValidFor || method.isValidFor(ctx, type)) allowedMethods.push(name_3.toUpperCase()); } response.setHeader('Allow', allowedMethods.join(',')); callback(null, ctx); } }; - RequestContext.prototype.noBodyExpected = function (callback) { + HTTPRequestContext.prototype.noBodyExpected = function (callback) { if (this.server.options.strictMode && this.headers.contentLength !== 0) { this.setCode(HTTPCodes_1.HTTPCodes.UnsupportedMediaType); this.exit(); @@ -156,7 +195,7 @@ var RequestContext = (function () { else callback(); }; - RequestContext.prototype.checkIfHeader = function (_fs, _path, _callback) { + HTTPRequestContext.prototype.checkIfHeader = function (_fs, _path, _callback) { var _this = this; var fs = _callback ? _fs : null; var path = _callback ? _path : null; @@ -183,7 +222,7 @@ var RequestContext = (function () { callback(); }); }; - RequestContext.prototype.askForAuthentication = function (checkForUser, callback) { + HTTPRequestContext.prototype.askForAuthentication = function (checkForUser, callback) { if (checkForUser && this.user !== null && !this.user.isDefaultUser) { callback(Errors_1.Errors.AlreadyAuthenticated); return; @@ -193,21 +232,7 @@ var RequestContext = (function () { this.response.setHeader(name_4, auth[name_4]); callback(null); }; - RequestContext.prototype.getResource = function (_path, _callback) { - var path = _callback ? new Path_1.Path(_path) : this.requested.path; - var callback = _callback ? _callback : _path; - this.server.getResource(this, path, callback); - }; - RequestContext.prototype.fullUri = function (uri) { - if (uri === void 0) { uri = null; } - if (!uri) - uri = this.requested.uri; - return (this.prefixUri() + uri).replace(/([^:])\/\//g, '$1/'); - }; - RequestContext.prototype.prefixUri = function () { - return 'http://' + this.headers.host.replace('/', ''); - }; - RequestContext.prototype.writeBody = function (xmlObject) { + HTTPRequestContext.prototype.writeBody = function (xmlObject) { var content = XML_1.XML.toXML(xmlObject); switch (this.headers.findBestAccept()) { default: @@ -225,7 +250,7 @@ var RequestContext = (function () { } this.responseBody = content; }; - RequestContext.prototype.setCode = function (code, message) { + HTTPRequestContext.prototype.setCode = function (code, message) { if (!message) message = http.STATUS_CODES[code]; if (!message) { @@ -236,7 +261,7 @@ var RequestContext = (function () { this.response.statusMessage = message; } }; - RequestContext.defaultStatusCode = function (error) { + HTTPRequestContext.defaultStatusCode = function (error) { var code = null; if (error === Errors_1.Errors.ResourceNotFound) code = HTTPCodes_1.HTTPCodes.NotFound; @@ -258,14 +283,13 @@ var RequestContext = (function () { code = HTTPCodes_1.HTTPCodes.Forbidden; return code; }; - RequestContext.prototype.setCodeFromError = function (error) { - var code = RequestContext.defaultStatusCode(error); + HTTPRequestContext.prototype.setCodeFromError = function (error) { + var code = HTTPRequestContext.defaultStatusCode(error); if (!code) return false; this.setCode(code); return true; }; - return RequestContext; -}()); -exports.RequestContext = RequestContext; -exports.default = RequestContext; + return HTTPRequestContext; +}(RequestContext)); +exports.HTTPRequestContext = HTTPRequestContext; diff --git a/lib/server/v2/WebDAVRequest.d.ts b/lib/server/v2/WebDAVRequest.d.ts index ebd7cb2a..7a5afae1 100644 --- a/lib/server/v2/WebDAVRequest.d.ts +++ b/lib/server/v2/WebDAVRequest.d.ts @@ -1,11 +1,11 @@ /// import { ResourceType } from '../../manager/v2/fileSystem/CommonTypes'; -import { RequestContext } from './RequestContext'; +import { HTTPRequestContext } from './RequestContext'; import { Readable } from 'stream'; -export { RequestContext } from './RequestContext'; +export { HTTPRequestContext } from './RequestContext'; export { HTTPCodes } from '../HTTPCodes'; export interface HTTPMethod { - unchunked?(ctx: RequestContext, data: Buffer, callback: () => void): void; - chunked?(ctx: RequestContext, inputStream: Readable, callback: () => void): void; - isValidFor?(type?: ResourceType): boolean; + unchunked?(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + chunked?(ctx: HTTPRequestContext, inputStream: Readable, callback: () => void): void; + isValidFor?(ctx: HTTPRequestContext, type?: ResourceType): boolean; } diff --git a/lib/server/v2/WebDAVRequest.js b/lib/server/v2/WebDAVRequest.js index 57577e6d..fc475e9e 100644 --- a/lib/server/v2/WebDAVRequest.js +++ b/lib/server/v2/WebDAVRequest.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var RequestContext_1 = require("./RequestContext"); -exports.RequestContext = RequestContext_1.RequestContext; +exports.HTTPRequestContext = RequestContext_1.HTTPRequestContext; var HTTPCodes_1 = require("../HTTPCodes"); exports.HTTPCodes = HTTPCodes_1.HTTPCodes; diff --git a/lib/server/v2/commands/Copy.d.ts b/lib/server/v2/commands/Copy.d.ts index b7ba7d56..96638eda 100644 --- a/lib/server/v2/commands/Copy.d.ts +++ b/lib/server/v2/commands/Copy.d.ts @@ -1,7 +1,7 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Copy.js b/lib/server/v2/commands/Copy.js index 3d7588d7..956c6388 100644 --- a/lib/server/v2/commands/Copy.js +++ b/lib/server/v2/commands/Copy.js @@ -7,7 +7,7 @@ var default_1 = (function () { default_1.prototype.unchunked = function (ctx, data, callback) { Move_1.execute(ctx, 'copy', 'canCopy', callback); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/commands/Delete.d.ts b/lib/server/v2/commands/Delete.d.ts index 3241a4b2..45975ce8 100644 --- a/lib/server/v2/commands/Delete.d.ts +++ b/lib/server/v2/commands/Delete.d.ts @@ -1,7 +1,7 @@ /// -import { RequestContext, HTTPMethod } from '../WebDAVRequest'; +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Delete.js b/lib/server/v2/commands/Delete.js index 2732c424..7ae54e5b 100644 --- a/lib/server/v2/commands/Delete.js +++ b/lib/server/v2/commands/Delete.js @@ -25,7 +25,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/commands/Get.d.ts b/lib/server/v2/commands/Get.d.ts index 3241a4b2..45975ce8 100644 --- a/lib/server/v2/commands/Get.d.ts +++ b/lib/server/v2/commands/Get.d.ts @@ -1,7 +1,7 @@ /// -import { RequestContext, HTTPMethod } from '../WebDAVRequest'; +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Get.js b/lib/server/v2/commands/Get.js index a00f115e..1c6808c3 100644 --- a/lib/server/v2/commands/Get.js +++ b/lib/server/v2/commands/Get.js @@ -114,7 +114,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return type && type.isFile; }; return default_1; diff --git a/lib/server/v2/commands/Head.d.ts b/lib/server/v2/commands/Head.d.ts index b7ba7d56..96638eda 100644 --- a/lib/server/v2/commands/Head.d.ts +++ b/lib/server/v2/commands/Head.d.ts @@ -1,7 +1,7 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Head.js b/lib/server/v2/commands/Head.js index 611c068a..eaaee678 100644 --- a/lib/server/v2/commands/Head.js +++ b/lib/server/v2/commands/Head.js @@ -46,7 +46,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return type && type.isFile; }; return default_1; diff --git a/lib/server/v2/commands/Lock.d.ts b/lib/server/v2/commands/Lock.d.ts index d3f99065..50f507f8 100644 --- a/lib/server/v2/commands/Lock.d.ts +++ b/lib/server/v2/commands/Lock.d.ts @@ -1,5 +1,5 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; } diff --git a/lib/server/v2/commands/Mkcol.d.ts b/lib/server/v2/commands/Mkcol.d.ts index b7ba7d56..96638eda 100644 --- a/lib/server/v2/commands/Mkcol.d.ts +++ b/lib/server/v2/commands/Mkcol.d.ts @@ -1,7 +1,7 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Mkcol.js b/lib/server/v2/commands/Mkcol.js index 8aae0a1d..bbbf70a0 100644 --- a/lib/server/v2/commands/Mkcol.js +++ b/lib/server/v2/commands/Mkcol.js @@ -40,7 +40,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !type; }; return default_1; diff --git a/lib/server/v2/commands/Move.d.ts b/lib/server/v2/commands/Move.d.ts index 1a1ac711..532e1664 100644 --- a/lib/server/v2/commands/Move.d.ts +++ b/lib/server/v2/commands/Move.d.ts @@ -1,8 +1,8 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; -export declare function execute(ctx: RequestContext, methodName: string, privilegeName: string, callback: () => void): void; +export declare function execute(ctx: HTTPRequestContext, methodName: string, privilegeName: string, callback: () => void): void; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Move.js b/lib/server/v2/commands/Move.js index 7e8424d8..163eea90 100644 --- a/lib/server/v2/commands/Move.js +++ b/lib/server/v2/commands/Move.js @@ -67,7 +67,7 @@ var default_1 = (function () { default_1.prototype.unchunked = function (ctx, data, callback) { execute(ctx, 'move', 'canMove', callback); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/commands/NotImplemented.d.ts b/lib/server/v2/commands/NotImplemented.d.ts index 32070ca7..9a14fb3b 100644 --- a/lib/server/v2/commands/NotImplemented.d.ts +++ b/lib/server/v2/commands/NotImplemented.d.ts @@ -1,5 +1,5 @@ /// -import { RequestContext, HTTPMethod } from '../WebDAVRequest'; +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; } diff --git a/lib/server/v2/commands/Options.d.ts b/lib/server/v2/commands/Options.d.ts index 32070ca7..9a14fb3b 100644 --- a/lib/server/v2/commands/Options.d.ts +++ b/lib/server/v2/commands/Options.d.ts @@ -1,5 +1,5 @@ /// -import { RequestContext, HTTPMethod } from '../WebDAVRequest'; +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; } diff --git a/lib/server/v2/commands/Propfind.d.ts b/lib/server/v2/commands/Propfind.d.ts index 3241a4b2..45975ce8 100644 --- a/lib/server/v2/commands/Propfind.d.ts +++ b/lib/server/v2/commands/Propfind.d.ts @@ -1,7 +1,7 @@ /// -import { RequestContext, HTTPMethod } from '../WebDAVRequest'; +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Propfind.js b/lib/server/v2/commands/Propfind.js index 1920b940..fd594c5a 100644 --- a/lib/server/v2/commands/Propfind.js +++ b/lib/server/v2/commands/Propfind.js @@ -330,7 +330,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/commands/Proppatch.d.ts b/lib/server/v2/commands/Proppatch.d.ts index b7ba7d56..96638eda 100644 --- a/lib/server/v2/commands/Proppatch.d.ts +++ b/lib/server/v2/commands/Proppatch.d.ts @@ -1,7 +1,7 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Proppatch.js b/lib/server/v2/commands/Proppatch.js index 66ece2ff..d494c6ea 100644 --- a/lib/server/v2/commands/Proppatch.js +++ b/lib/server/v2/commands/Proppatch.js @@ -153,7 +153,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/commands/Put.d.ts b/lib/server/v2/commands/Put.d.ts index 06be59f0..61d2f26b 100644 --- a/lib/server/v2/commands/Put.d.ts +++ b/lib/server/v2/commands/Put.d.ts @@ -1,8 +1,8 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; import { Readable } from 'stream'; export default class implements HTTPMethod { - isValidFor(type: ResourceType): boolean; - chunked(ctx: RequestContext, inputStream: Readable, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; + chunked(ctx: HTTPRequestContext, inputStream: Readable, callback: () => void): void; } diff --git a/lib/server/v2/commands/Put.js b/lib/server/v2/commands/Put.js index 22b8ad59..297ec5e5 100644 --- a/lib/server/v2/commands/Put.js +++ b/lib/server/v2/commands/Put.js @@ -5,7 +5,7 @@ var Errors_1 = require("../../../Errors"); var default_1 = (function () { function default_1() { } - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !type || type.isFile; }; default_1.prototype.chunked = function (ctx, inputStream, callback) { diff --git a/lib/server/v2/commands/Unlock.d.ts b/lib/server/v2/commands/Unlock.d.ts index b7ba7d56..96638eda 100644 --- a/lib/server/v2/commands/Unlock.d.ts +++ b/lib/server/v2/commands/Unlock.d.ts @@ -1,7 +1,7 @@ /// -import { HTTPMethod, RequestContext } from '../WebDAVRequest'; +import { HTTPMethod, HTTPRequestContext } from '../WebDAVRequest'; import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes'; export default class implements HTTPMethod { - unchunked(ctx: RequestContext, data: Buffer, callback: () => void): void; - isValidFor(type: ResourceType): boolean; + unchunked(ctx: HTTPRequestContext, data: Buffer, callback: () => void): void; + isValidFor(ctx: HTTPRequestContext, type: ResourceType): boolean; } diff --git a/lib/server/v2/commands/Unlock.js b/lib/server/v2/commands/Unlock.js index d95bd4ca..e7c02168 100644 --- a/lib/server/v2/commands/Unlock.js +++ b/lib/server/v2/commands/Unlock.js @@ -73,7 +73,7 @@ var default_1 = (function () { }); }); }; - default_1.prototype.isValidFor = function (type) { + default_1.prototype.isValidFor = function (ctx, type) { return !!type; }; return default_1; diff --git a/lib/server/v2/webDAVServer/BeforeAfter.d.ts b/lib/server/v2/webDAVServer/BeforeAfter.d.ts index 0d137885..7b9b1469 100644 --- a/lib/server/v2/webDAVServer/BeforeAfter.d.ts +++ b/lib/server/v2/webDAVServer/BeforeAfter.d.ts @@ -1,6 +1,6 @@ -import { RequestContext } from '../WebDAVRequest'; +import { HTTPRequestContext } from '../WebDAVRequest'; export interface RequestListener { - (ctx: RequestContext, next: () => void): void; + (ctx: HTTPRequestContext, next: () => void): void; } -export declare function invokeBeforeRequest(base: RequestContext, callback: any): void; -export declare function invokeAfterRequest(base: RequestContext, callback: any): void; +export declare function invokeBeforeRequest(base: HTTPRequestContext, callback: any): void; +export declare function invokeAfterRequest(base: HTTPRequestContext, callback: any): void; diff --git a/lib/server/v2/webDAVServer/StartStop.js b/lib/server/v2/webDAVServer/StartStop.js index dcfda668..6d775a45 100644 --- a/lib/server/v2/webDAVServer/StartStop.js +++ b/lib/server/v2/webDAVServer/StartStop.js @@ -30,7 +30,7 @@ function start(port, callback) { var method = _this.methods[_this.normalizeMethodName(req.method)]; if (!method) method = _this.unknownMethod; - WebDAVRequest_1.RequestContext.create(_this, req, res, function (e, base) { + WebDAVRequest_1.HTTPRequestContext.create(_this, req, res, function (e, base) { if (e) { if (e === Errors_1.Errors.AuenticationPropertyMissing || e === Errors_1.Errors.MissingAuthorisationHeader || e === Errors_1.Errors.BadAuthentication || e === Errors_1.Errors.WrongHeaderFormat) base.setCode(WebDAVRequest_1.HTTPCodes.Unauthorized); diff --git a/lib/server/v2/webDAVServer/WebDAVServer.d.ts b/lib/server/v2/webDAVServer/WebDAVServer.d.ts index 4381a7d9..541f499f 100644 --- a/lib/server/v2/webDAVServer/WebDAVServer.d.ts +++ b/lib/server/v2/webDAVServer/WebDAVServer.d.ts @@ -1,6 +1,6 @@ /// import { WebDAVServerOptions } from '../WebDAVServerOptions'; -import { RequestContext, RequestContextExternalOptions } from '../RequestContext'; +import { ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext'; import { HTTPMethod } from '../WebDAVRequest'; import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication'; import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager'; @@ -32,12 +32,13 @@ export declare class WebDAVServer { [path: string]: FileSystem; }; constructor(options?: WebDAVServerOptions); - createExternalContext(): RequestContext; - createExternalContext(callback: (error: Error, ctx: RequestContext) => void): RequestContext; - createExternalContext(options: RequestContextExternalOptions): RequestContext; - createExternalContext(options: RequestContextExternalOptions, callback: (error: Error, ctx: RequestContext) => void): RequestContext; + createExternalContext(): ExternalRequestContext; + createExternalContext(callback: (error: Error, ctx: ExternalRequestContext) => void): ExternalRequestContext; + createExternalContext(options: RequestContextExternalOptions): ExternalRequestContext; + createExternalContext(options: RequestContextExternalOptions, callback: (error: Error, ctx: ExternalRequestContext) => void): ExternalRequestContext; rootFileSystem(): FileSystem; getResource(ctx: RequestContext, path: Path | string, callback: ReturnCallback): void; + getResourceSync(ctx: RequestContext, path: Path | string): Resource; setFileSystem(path: Path | string, fs: FileSystem, callback: (successed?: boolean) => void): void; setFileSystem(path: Path | string, fs: FileSystem, override: boolean, callback: (successed?: boolean) => void): void; setFileSystemSync(path: Path | string, fs: FileSystem, override?: boolean): boolean; diff --git a/lib/server/v2/webDAVServer/WebDAVServer.js b/lib/server/v2/webDAVServer/WebDAVServer.js index 63847b04..dd89bceb 100644 --- a/lib/server/v2/webDAVServer/WebDAVServer.js +++ b/lib/server/v2/webDAVServer/WebDAVServer.js @@ -35,7 +35,7 @@ var WebDAVServer = (function () { this.method(k, new commands[k]()); } WebDAVServer.prototype.createExternalContext = function (_options, _callback) { - return RequestContext_1.RequestContext.createExternal(this, _options, _callback); + return RequestContext_1.ExternalRequestContext.create(this, _options, _callback); }; WebDAVServer.prototype.rootFileSystem = function () { return this.fileSystems['/']; @@ -46,6 +46,11 @@ var WebDAVServer = (function () { callback(null, fs.resource(ctx, subPath)); }); }; + WebDAVServer.prototype.getResourceSync = function (ctx, path) { + path = new Path_1.Path(path); + var info = this.getFileSystemSync(path); + return info.fs.resource(ctx, info.subPath); + }; WebDAVServer.prototype.setFileSystem = function (path, fs, _override, _callback) { var override = _callback ? _override : undefined; var callback = _callback ? _callback : _override; diff --git a/lib/user/v2/authentication/HTTPAuthentication.d.ts b/lib/user/v2/authentication/HTTPAuthentication.d.ts index cd855613..a8334aec 100644 --- a/lib/user/v2/authentication/HTTPAuthentication.d.ts +++ b/lib/user/v2/authentication/HTTPAuthentication.d.ts @@ -1,8 +1,8 @@ -import { RequestContext } from '../../../server/v2/RequestContext'; +import { HTTPRequestContext } from '../../../server/v2/RequestContext'; import { IUser } from '../IUser'; export interface HTTPAuthentication { askForAuthentication(): { [headeName: string]: string; }; - getUser(arg: RequestContext, callback: (error: Error, user?: IUser) => void): void; + getUser(arg: HTTPRequestContext, callback: (error: Error, user?: IUser) => void): void; } diff --git a/lib/user/v2/authentication/HTTPBasicAuthentication.d.ts b/lib/user/v2/authentication/HTTPBasicAuthentication.d.ts index 7e6592d0..b65b4225 100644 --- a/lib/user/v2/authentication/HTTPBasicAuthentication.d.ts +++ b/lib/user/v2/authentication/HTTPBasicAuthentication.d.ts @@ -1,6 +1,6 @@ -import { HTTPAuthentication } from './HTTPAuthentication'; -import { RequestContext } from '../../../server/v2/RequestContext'; import { ITestableUserManager } from '../userManager/ITestableUserManager'; +import { HTTPAuthentication } from './HTTPAuthentication'; +import { HTTPRequestContext } from '../../../server/v2/RequestContext'; import { IUser } from '../IUser'; export declare class HTTPBasicAuthentication implements HTTPAuthentication { userManager: ITestableUserManager; @@ -9,5 +9,5 @@ export declare class HTTPBasicAuthentication implements HTTPAuthentication { askForAuthentication(): { 'WWW-Authenticate': string; }; - getUser(arg: RequestContext, callback: (error: Error, user: IUser) => void): void; + getUser(arg: HTTPRequestContext, callback: (error: Error, user: IUser) => void): void; } diff --git a/lib/user/v2/authentication/HTTPDigestAuthentication.d.ts b/lib/user/v2/authentication/HTTPDigestAuthentication.d.ts index 00542d9f..ce84e68d 100644 --- a/lib/user/v2/authentication/HTTPDigestAuthentication.d.ts +++ b/lib/user/v2/authentication/HTTPDigestAuthentication.d.ts @@ -1,5 +1,5 @@ import { HTTPAuthentication } from './HTTPAuthentication'; -import { RequestContext } from '../../../server/v2/RequestContext'; +import { HTTPRequestContext } from '../../../server/v2/RequestContext'; import { IListUserManager } from '../userManager/IListUserManager'; import { IUser } from '../IUser'; export declare class HTTPDigestAuthentication implements HTTPAuthentication { @@ -11,5 +11,5 @@ export declare class HTTPDigestAuthentication implements HTTPAuthentication { askForAuthentication(): { 'WWW-Authenticate': string; }; - getUser(arg: RequestContext, callback: (error: Error, user: IUser) => void): void; + getUser(arg: HTTPRequestContext, callback: (error: Error, user: IUser) => void): void; } diff --git a/lib/user/v2/simple/SimpleUserManager.d.ts b/lib/user/v2/simple/SimpleUserManager.d.ts index f3407f68..abc36989 100644 --- a/lib/user/v2/simple/SimpleUserManager.d.ts +++ b/lib/user/v2/simple/SimpleUserManager.d.ts @@ -1,5 +1,5 @@ -import { IListUserManager } from '../userManager/IListUserManager'; import { ITestableUserManager } from '../userManager/ITestableUserManager'; +import { IListUserManager } from '../userManager/IListUserManager'; import { IUser } from '../IUser'; export declare class SimpleUserManager implements ITestableUserManager, IListUserManager { protected users: any; diff --git a/src/server/v2/RequestContext.ts b/src/server/v2/RequestContext.ts index 48671cc7..cc768245 100644 --- a/src/server/v2/RequestContext.ts +++ b/src/server/v2/RequestContext.ts @@ -18,7 +18,7 @@ export class RequestContextHeaders depth : number host : string - constructor(protected request : http.IncomingMessage) + constructor(protected headers : { [name : string] : string }) { this.isSource = this.find('source', 'F').toUpperCase() === 'T' || this.find('translate', 'T').toUpperCase() === 'F'; this.host = this.find('Host', 'localhost'); @@ -50,10 +50,10 @@ export class RequestContextHeaders { name = name.replace(/(-| )/g, '').toLowerCase(); - for(const k in this.request.headers) + for(const k in this.headers) if(k.replace(/(-| )/g, '').toLowerCase() === name) { - const value = this.request.headers[k].trim(); + const value = this.headers[k].trim(); if(value.length !== 0) return value; } @@ -109,37 +109,65 @@ export class DefaultRequestContextExternalOptions implements RequestContextExter export class RequestContext { - responseBody : string requested : RequestedResource headers : RequestContextHeaders + server : WebDAVServer user : IUser - - protected constructor( - public server : WebDAVServer, - public request : http.IncomingMessage, - public response : http.ServerResponse, - public exit : () => void - ) { - this.responseBody = undefined; - this.headers = new RequestContextHeaders(request); + + protected constructor(server : WebDAVServer, uri : string, headers : { [name : string] : string }) + { + this.headers = new RequestContextHeaders(headers); + this.server = server; - const uri = url.parse(request.url).pathname; + uri = url.parse(uri).pathname; this.requested = { uri, path: new Path(uri) }; } + + getResource(callback : ReturnCallback) + getResource(path : Path | string, callback : ReturnCallback) + getResource(_path : Path | string | ReturnCallback, _callback ?: ReturnCallback) + { + const path = _callback ? new Path(_path as Path | string) : this.requested.path; + const callback = _callback ? _callback : _path as ReturnCallback; - static createExternal(server : WebDAVServer) : RequestContext - static createExternal(server : WebDAVServer, callback : (error : Error, ctx : RequestContext) => void) : RequestContext - static createExternal(server : WebDAVServer, options : RequestContextExternalOptions) : RequestContext - static createExternal(server : WebDAVServer, options : RequestContextExternalOptions, callback : (error : Error, ctx : RequestContext) => void) : RequestContext - static createExternal(server : WebDAVServer, _options ?: RequestContextExternalOptions | ((error : Error, ctx : RequestContext) => void), _callback ?: (error : Error, ctx : RequestContext) => void) : RequestContext + this.server.getResource(this, path, callback); + } + + getResourceSync(path ?: Path | string) : Resource + { + path = path ? path : this.requested.path; + return this.server.getResourceSync(this, path); + } + + fullUri(uri : string = null) + { + if(!uri) + uri = this.requested.uri; + + return (this.prefixUri() + uri).replace(/([^:])\/\//g, '$1/'); + } + + prefixUri() + { + return 'http://' + this.headers.host.replace('/', ''); + } +} + +export class ExternalRequestContext extends RequestContext +{ + static create(server : WebDAVServer) : ExternalRequestContext + static create(server : WebDAVServer, callback : (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext + static create(server : WebDAVServer, options : RequestContextExternalOptions) : ExternalRequestContext + static create(server : WebDAVServer, options : RequestContextExternalOptions, callback : (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext + static create(server : WebDAVServer, _options ?: RequestContextExternalOptions | ((error : Error, ctx : ExternalRequestContext) => void), _callback ?: (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext { const defaultValues = new DefaultRequestContextExternalOptions(); const options = _options && _options.constructor !== Function ? _options as RequestContextExternalOptions : defaultValues; - const callback = _callback ? _callback : _options && _options.constructor === Function ? _options as ((error : Error, ctx : RequestContext) => void) : () => {}; + const callback = _callback ? _callback : _options && _options.constructor === Function ? _options as ((error : Error, ctx : ExternalRequestContext) => void) : () => {}; if(defaultValues !== options) { @@ -148,25 +176,42 @@ export class RequestContext options[name] = defaultValues[name]; } - const ctx = new RequestContext(server, { - headers: options.headers, - url: options.url - } as any, null, null); + const ctx = new ExternalRequestContext(server, options.url, options.headers); if(options.user) + { ctx.user = options.user; - else - server.httpAuthentication.getUser(ctx, (e, user) => { - ctx.user = options.user; - callback(e, ctx); - }) + process.nextTick(() => callback(null, ctx)); + } return ctx; } +} - static create(server : WebDAVServer, request : http.IncomingMessage, response : http.ServerResponse, callback : (error : Error, ctx : RequestContext) => void) +export class HTTPRequestContext extends RequestContext +{ + responseBody : string + request : http.IncomingMessage + response : http.ServerResponse + exit : () => void + + protected constructor( + server : WebDAVServer, + request : http.IncomingMessage, + response : http.ServerResponse, + exit : () => void + ) { + super(server, request.url, request.headers); + + this.responseBody = undefined; + this.response = response; + this.request = request; + this.exit = exit; + } + + static create(server : WebDAVServer, request : http.IncomingMessage, response : http.ServerResponse, callback : (error : Error, ctx : HTTPRequestContext) => void) { - const ctx = new RequestContext(server, request, response, null); + const ctx = new HTTPRequestContext(server, request, response, null); response.setHeader('DAV', '1,2'); response.setHeader('Server', server.options.serverName + '/' + server.options.version); @@ -205,7 +250,7 @@ export class RequestContext for(const name in server.methods) { const method = server.methods[name]; - if(!method.isValidFor || method.isValidFor(type)) + if(!method.isValidFor || method.isValidFor(ctx, type)) allowedMethods.push(name.toUpperCase()); } @@ -277,29 +322,6 @@ export class RequestContext callback(null); } - getResource(callback : ReturnCallback) - getResource(path : Path | string, callback : ReturnCallback) - getResource(_path : Path | string | ReturnCallback, _callback ?: ReturnCallback) - { - const path = _callback ? new Path(_path as Path | string) : this.requested.path; - const callback = _callback ? _callback : _path as ReturnCallback; - - this.server.getResource(this, path, callback); - } - - fullUri(uri : string = null) - { - if(!uri) - uri = this.requested.uri; - - return (this.prefixUri() + uri).replace(/([^:])\/\//g, '$1/'); - } - - prefixUri() - { - return 'http://' + this.headers.host.replace('/', ''); - } - writeBody(xmlObject : XMLElement | object) { let content = XML.toXML(xmlObject); @@ -365,7 +387,7 @@ export class RequestContext } setCodeFromError(error : Error) : boolean { - const code = RequestContext.defaultStatusCode(error); + const code = HTTPRequestContext.defaultStatusCode(error); if(!code) return false; @@ -374,4 +396,3 @@ export class RequestContext return true; } } -export default RequestContext; diff --git a/src/server/v2/WebDAVRequest.ts b/src/server/v2/WebDAVRequest.ts index ee5f3966..62f3d3b6 100644 --- a/src/server/v2/WebDAVRequest.ts +++ b/src/server/v2/WebDAVRequest.ts @@ -1,13 +1,13 @@ import { ResourceType } from '../../manager/v2/fileSystem/CommonTypes' -import { RequestContext } from './RequestContext' +import { HTTPRequestContext } from './RequestContext' import { Readable } from 'stream' -export { RequestContext } from './RequestContext' +export { HTTPRequestContext } from './RequestContext' export { HTTPCodes } from '../HTTPCodes' export interface HTTPMethod { - unchunked?(ctx : RequestContext, data : Buffer, callback : () => void) : void - chunked?(ctx : RequestContext, inputStream : Readable, callback : () => void) : void - isValidFor?(type ?: ResourceType) : boolean + unchunked?(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void + chunked?(ctx : HTTPRequestContext, inputStream : Readable, callback : () => void) : void + isValidFor?(ctx : HTTPRequestContext, type ?: ResourceType) : boolean } diff --git a/src/server/v2/commands/Copy.ts b/src/server/v2/commands/Copy.ts index 983817cc..040e9f7f 100644 --- a/src/server/v2/commands/Copy.ts +++ b/src/server/v2/commands/Copy.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType, SimpleCallback } from '../../../manager/v2/fileSystem/CommonTypes' import { Path } from '../../../manager/v2/Path' import { Workflow } from '../../../helper/Workflow' @@ -8,12 +8,12 @@ import { execute } from './Move' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { execute(ctx, 'copy', 'canCopy', callback); } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/commands/Delete.ts b/src/server/v2/commands/Delete.ts index 982c61fe..be4da4a1 100644 --- a/src/server/v2/commands/Delete.ts +++ b/src/server/v2/commands/Delete.ts @@ -1,9 +1,9 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.noBodyExpected(() => { ctx.getResource((e, r) => { @@ -28,7 +28,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/commands/Get.ts b/src/server/v2/commands/Get.ts index c3616f72..faa5016a 100644 --- a/src/server/v2/commands/Get.ts +++ b/src/server/v2/commands/Get.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { Errors } from '../../../Errors' import { Transform } from 'stream' @@ -44,7 +44,7 @@ class RangedStream extends Transform export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.noBodyExpected(() => { ctx.getResource((e, r) => { @@ -126,7 +126,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return type && type.isFile; } diff --git a/src/server/v2/commands/Head.ts b/src/server/v2/commands/Head.ts index 44b5ffc8..6cfbc1e2 100644 --- a/src/server/v2/commands/Head.ts +++ b/src/server/v2/commands/Head.ts @@ -1,10 +1,10 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { Errors } from '../../../Errors' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.noBodyExpected(() => { ctx.getResource((e, r) => { @@ -56,7 +56,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return type && type.isFile; } diff --git a/src/server/v2/commands/Lock.ts b/src/server/v2/commands/Lock.ts index 47a82c67..4e587031 100644 --- a/src/server/v2/commands/Lock.ts +++ b/src/server/v2/commands/Lock.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType, SimpleCallback } from '../../../manager/v2/fileSystem/CommonTypes' import { Resource } from '../../../manager/v2/fileSystem/Resource' import { extractOneToken } from '../../../helper/IfParser' @@ -10,7 +10,7 @@ import { Lock } from '../../../resource/lock/Lock' import { XML } from '../../../helper/XML' import * as path from 'path' -function createResponse(ctx : RequestContext, lock : Lock) +function createResponse(ctx : HTTPRequestContext, lock : Lock) { const prop = XML.createElement('D:prop', { 'xmlns:D': 'DAV:' @@ -28,7 +28,7 @@ function createResponse(ctx : RequestContext, lock : Lock) return prop; } -function createLock(ctx : RequestContext, data : Buffer, callback) +function createLock(ctx : HTTPRequestContext, data : Buffer, callback) { try { @@ -111,7 +111,7 @@ function createLock(ctx : RequestContext, data : Buffer, callback) } } -function refreshLock(ctx : RequestContext, lockUUID : string, callback) +function refreshLock(ctx : HTTPRequestContext, lockUUID : string, callback) { ctx.getResource((e, r) => { //ctx.requirePrivilege([ 'canSetLock', 'canGetLock' ], r, () => { @@ -143,7 +143,7 @@ function refreshLock(ctx : RequestContext, lockUUID : string, callback) export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { if(!ctx.user) { diff --git a/src/server/v2/commands/Mkcol.ts b/src/server/v2/commands/Mkcol.ts index c638129e..34b63ab1 100644 --- a/src/server/v2/commands/Mkcol.ts +++ b/src/server/v2/commands/Mkcol.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { Path } from '../../../manager/v2/Path' import { Errors } from '../../../Errors' @@ -6,7 +6,7 @@ import * as path from 'path' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.noBodyExpected(() => { ctx.checkIfHeader(undefined, () => { @@ -46,7 +46,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !type; } diff --git a/src/server/v2/commands/Move.ts b/src/server/v2/commands/Move.ts index a088b5fc..9f616706 100644 --- a/src/server/v2/commands/Move.ts +++ b/src/server/v2/commands/Move.ts @@ -1,10 +1,10 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { StandardMethods } from '../../../manager/v2/fileSystem/StandardMethods' import { Path } from '../../../manager/v2/Path' import { Errors } from '../../../Errors' -export function execute(ctx : RequestContext, methodName : string, privilegeName : string, callback : () => void) +export function execute(ctx : HTTPRequestContext, methodName : string, privilegeName : string, callback : () => void) { ctx.noBodyExpected(() => { ctx.getResource((e, r) => { @@ -77,12 +77,12 @@ export function execute(ctx : RequestContext, methodName : string, privilegeName export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { execute(ctx, 'move', 'canMove', callback); } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/commands/NotImplemented.ts b/src/server/v2/commands/NotImplemented.ts index 1bb2b923..26abf04b 100644 --- a/src/server/v2/commands/NotImplemented.ts +++ b/src/server/v2/commands/NotImplemented.ts @@ -1,8 +1,8 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.setCode(HTTPCodes.NotImplemented); callback(); diff --git a/src/server/v2/commands/Options.ts b/src/server/v2/commands/Options.ts index 01fcae87..ca73b01d 100644 --- a/src/server/v2/commands/Options.ts +++ b/src/server/v2/commands/Options.ts @@ -1,8 +1,8 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.noBodyExpected(() => { ctx.setCode(HTTPCodes.OK); diff --git a/src/server/v2/commands/Propfind.ts b/src/server/v2/commands/Propfind.ts index 31d6d935..8dd98506 100644 --- a/src/server/v2/commands/Propfind.ts +++ b/src/server/v2/commands/Propfind.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' import { XML, XMLElement } from '../../../helper/XML' import { Workflow } from '../../../helper/Workflow' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' @@ -34,7 +34,7 @@ function dateISO8601(ticks : number) : string } /* -function lockDiscovery(lockDiscoveryCache : any, ctx : RequestContext, path : Path, resource : IResource, callback : ReturnCallback) +function lockDiscovery(lockDiscoveryCache : any, ctx : HTTPRequestContext, path : Path, resource : IResource, callback : ReturnCallback) { const cached = lockDiscoveryCache[path.toString()]; if(cached) @@ -97,7 +97,7 @@ interface PropertyRule mustDisplayValue : (propertyName : string) => boolean } -function parseRequestBody(ctx : RequestContext, data : Buffer) : PropertyRule +function parseRequestBody(ctx : HTTPRequestContext, data : Buffer) : PropertyRule { const allTrue : PropertyRule = { leftElements: [], @@ -153,7 +153,7 @@ function propstatStatus(status : number) export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.getResource((e, resource) => { const lockDiscoveryCache = {}; @@ -494,7 +494,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/commands/Proppatch.ts b/src/server/v2/commands/Proppatch.ts index 062a7c37..728a56e2 100644 --- a/src/server/v2/commands/Proppatch.ts +++ b/src/server/v2/commands/Proppatch.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { IPropertyManager } from '../../../manager/v2/fileSystem/PropertyManager' import { STATUS_CODES } from 'http' @@ -8,7 +8,7 @@ import { Errors } from '../../../Errors' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { ctx.getResource((e, r) => { ctx.checkIfHeader(r, () => { @@ -186,7 +186,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/commands/Put.ts b/src/server/v2/commands/Put.ts index 3e26b46e..449f3d5a 100644 --- a/src/server/v2/commands/Put.ts +++ b/src/server/v2/commands/Put.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType, OpenWriteStreamMode } from '../../../manager/v2/fileSystem/CommonTypes' import { Errors, HTTPError } from '../../../Errors' import { Readable } from 'stream' @@ -6,12 +6,12 @@ import * as path from 'path' export default class implements HTTPMethod { - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !type || type.isFile; } - chunked(ctx : RequestContext, inputStream : Readable, callback : () => void) + chunked(ctx : HTTPRequestContext, inputStream : Readable, callback : () => void) { const targetSource = ctx.headers.isSource; diff --git a/src/server/v2/commands/Unlock.ts b/src/server/v2/commands/Unlock.ts index c08f9727..dfaf0f51 100644 --- a/src/server/v2/commands/Unlock.ts +++ b/src/server/v2/commands/Unlock.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, HTTPMethod, RequestContext } from '../WebDAVRequest' +import { HTTPCodes, HTTPMethod, HTTPRequestContext } from '../WebDAVRequest' import { ResourceType } from '../../../manager/v2/fileSystem/CommonTypes' import { STATUS_CODES } from 'http' import { LockScope } from '../../../resource/lock/LockScope' @@ -10,7 +10,7 @@ import { XML } from '../../../helper/XML' export default class implements HTTPMethod { - unchunked(ctx : RequestContext, data : Buffer, callback : () => void) : void + unchunked(ctx : HTTPRequestContext, data : Buffer, callback : () => void) : void { if(!ctx.user) { @@ -94,7 +94,7 @@ export default class implements HTTPMethod }) } - isValidFor(type : ResourceType) + isValidFor(ctx : HTTPRequestContext, type : ResourceType) { return !!type; } diff --git a/src/server/v2/webDAVServer/BeforeAfter.ts b/src/server/v2/webDAVServer/BeforeAfter.ts index 396c19cc..dd10919e 100644 --- a/src/server/v2/webDAVServer/BeforeAfter.ts +++ b/src/server/v2/webDAVServer/BeforeAfter.ts @@ -1,11 +1,11 @@ -import { RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' export interface RequestListener { - (ctx : RequestContext, next : () => void) : void + (ctx : HTTPRequestContext, next : () => void) : void } -function invokeBARequest(collection : RequestListener[], base : RequestContext, callback) +function invokeBARequest(collection : RequestListener[], base : HTTPRequestContext, callback) { function callCallback() { @@ -33,11 +33,11 @@ function invokeBARequest(collection : RequestListener[], base : RequestContext, next(); } -export function invokeBeforeRequest(base : RequestContext, callback) +export function invokeBeforeRequest(base : HTTPRequestContext, callback) { invokeBARequest(this.beforeManagers, base, callback); } -export function invokeAfterRequest(base : RequestContext, callback) +export function invokeAfterRequest(base : HTTPRequestContext, callback) { invokeBARequest(this.afterManagers, base, callback); } \ No newline at end of file diff --git a/src/server/v2/webDAVServer/Persistence.ts b/src/server/v2/webDAVServer/Persistence.ts index 571114aa..fda8065b 100644 --- a/src/server/v2/webDAVServer/Persistence.ts +++ b/src/server/v2/webDAVServer/Persistence.ts @@ -1,10 +1,9 @@ -//import { RootFSManager, VirtualFSManager, PhysicalFSManager } from '../../manager/export' import { FileSystem } from '../../../manager/v2/fileSystem/FileSystem' import { SimpleCallback } from '../../../manager/v2/fileSystem/CommonTypes' import { FileSystemSerializer, serialize, unserialize, SerializedData } from '../../../manager/v2/fileSystem/Serialization' import { VirtualSerializer } from '../../../manager/v2/instances/VirtualFileSystem' import { PhysicalSerializer } from '../../../manager/v2/instances/PhysicalFileSystem' -import { RequestContext } from '../RequestContext' +import { HTTPRequestContext } from '../RequestContext' import { IAutoSave, IAutoLoad } from '../WebDAVServerOptions' import { Readable } from 'stream' import * as zlib from 'zlib' @@ -83,7 +82,7 @@ export function autoSave(options : IAutoSave) let saving = false; let saveRequested = false; - this.afterRequest((ctx : RequestContext, next) => { + this.afterRequest((ctx : HTTPRequestContext, next) => { switch(ctx.request.method.toUpperCase()) { case 'PROPPATCH': diff --git a/src/server/v2/webDAVServer/StartStop.ts b/src/server/v2/webDAVServer/StartStop.ts index 5badb076..7e440633 100644 --- a/src/server/v2/webDAVServer/StartStop.ts +++ b/src/server/v2/webDAVServer/StartStop.ts @@ -1,4 +1,4 @@ -import { HTTPCodes, RequestContext, HTTPMethod } from '../WebDAVRequest' +import { HTTPCodes, HTTPRequestContext, HTTPMethod } from '../WebDAVRequest' import { WebDAVServerStartCallback } from './WebDAVServer' import { Writable, Readable } from 'stream' import { Errors, HTTPError } from '../../../Errors' @@ -43,7 +43,7 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We if(!method) method = this.unknownMethod; - RequestContext.create(this, req, res, (e, base) => { + HTTPRequestContext.create(this, req, res, (e, base) => { if(e) { if(e === Errors.AuenticationPropertyMissing || e === Errors.MissingAuthorisationHeader || e === Errors.BadAuthentication || e === Errors.WrongHeaderFormat) diff --git a/src/server/v2/webDAVServer/Types.ts b/src/server/v2/webDAVServer/Types.ts deleted file mode 100644 index 2688ea27..00000000 --- a/src/server/v2/webDAVServer/Types.ts +++ /dev/null @@ -1,25 +0,0 @@ -/*import { WebDAVServerOptions, setDefaultServerOptions } from '../WebDAVServerOptions' -import { SerializedObject, unserialize, serialize } from '../../manager/ISerializer' -import { HTTPCodes, MethodCallArgs, WebDAVRequest } from '../WebDAVRequest' -import { IResource, ReturnCallback } from '../../resource/IResource' -import { FakePrivilegeManager } from '../../user/privilege/FakePrivilegeManager' -import { HTTPAuthentication } from '../../user/authentication/HTTPAuthentication' -import { IPrivilegeManager } from '../../user/privilege/IPrivilegeManager' -import { SimpleUserManager } from '../../user/simple/SimpleUserManager' -import { FSManager, FSPath } from '../../manager/FSManager' -import { Errors, HTTPError } from '../../Errors' -import { RootResource } from '../../resource/std/RootResource' -import { IUserManager } from '../../user/IUserManager' -import Commands from '../commands/Commands'*/ -import * as http from 'http' - -/* -export interface IResourceTreeNode -{ - r ?: IResource - resource ?: IResource - c ?: ResourceTreeNode[] - children ?: ResourceTreeNode[] -} -export type ResourceTreeNode = IResourceTreeNode | IResource | IResourceTreeNode[] | IResource[]; -*/ \ No newline at end of file diff --git a/src/server/v2/webDAVServer/WebDAVServer.ts b/src/server/v2/webDAVServer/WebDAVServer.ts index 637a14a6..1d11af44 100644 --- a/src/server/v2/webDAVServer/WebDAVServer.ts +++ b/src/server/v2/webDAVServer/WebDAVServer.ts @@ -1,5 +1,5 @@ import { WebDAVServerOptions, setDefaultServerOptions } from '../WebDAVServerOptions' -import { RequestContext, RequestContextExternalOptions } from '../RequestContext' +import { HTTPRequestContext, ExternalRequestContext, RequestContextExternalOptions, RequestContext } from '../RequestContext' import { HTTPCodes, HTTPMethod } from '../WebDAVRequest' import { HTTPAuthentication } from '../../../user/v2/authentication/HTTPAuthentication' import { PrivilegeManager } from '../../../user/v2/privilege/PrivilegeManager' @@ -59,13 +59,13 @@ export class WebDAVServer this.method(k, new commands[k]()); } - createExternalContext() : RequestContext - createExternalContext(callback : (error : Error, ctx : RequestContext) => void) : RequestContext - createExternalContext(options : RequestContextExternalOptions) : RequestContext - createExternalContext(options : RequestContextExternalOptions, callback : (error : Error, ctx : RequestContext) => void) : RequestContext - createExternalContext(_options ?: RequestContextExternalOptions | ((error : Error, ctx : RequestContext) => void), _callback ?: (error : Error, ctx : RequestContext) => void) : RequestContext + createExternalContext() : ExternalRequestContext + createExternalContext(callback : (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext + createExternalContext(options : RequestContextExternalOptions) : ExternalRequestContext + createExternalContext(options : RequestContextExternalOptions, callback : (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext + createExternalContext(_options ?: RequestContextExternalOptions | ((error : Error, ctx : ExternalRequestContext) => void), _callback ?: (error : Error, ctx : ExternalRequestContext) => void) : ExternalRequestContext { - return RequestContext.createExternal(this, _options, _callback); + return ExternalRequestContext.create(this, _options, _callback); } rootFileSystem() : FileSystem @@ -81,6 +81,13 @@ export class WebDAVServer callback(null, fs.resource(ctx, subPath)); }) } + getResourceSync(ctx : RequestContext, path : Path | string) : Resource + { + path = new Path(path); + + const info = this.getFileSystemSync(path); + return info.fs.resource(ctx, info.subPath); + } setFileSystem(path : Path | string, fs : FileSystem, callback : (successed ?: boolean) => void) : void setFileSystem(path : Path | string, fs : FileSystem, override : boolean, callback : (successed ?: boolean) => void) : void diff --git a/src/user/v2/authentication/HTTPAuthentication.ts b/src/user/v2/authentication/HTTPAuthentication.ts index e7d9e992..6fa1708d 100644 --- a/src/user/v2/authentication/HTTPAuthentication.ts +++ b/src/user/v2/authentication/HTTPAuthentication.ts @@ -1,4 +1,4 @@ -import { RequestContext } from '../../../server/v2/RequestContext' +import { HTTPRequestContext } from '../../../server/v2/RequestContext' import { IUserManager } from '../IUserManager' import { IUser } from '../IUser' @@ -7,5 +7,5 @@ export interface HTTPAuthentication askForAuthentication() : { [headeName : string] : string } - getUser(arg : RequestContext, callback : (error : Error, user ?: IUser) => void) : void + getUser(arg : HTTPRequestContext, callback : (error : Error, user ?: IUser) => void) : void } diff --git a/src/user/v2/authentication/HTTPBasicAuthentication.ts b/src/user/v2/authentication/HTTPBasicAuthentication.ts index e1603fed..bb369c04 100644 --- a/src/user/v2/authentication/HTTPBasicAuthentication.ts +++ b/src/user/v2/authentication/HTTPBasicAuthentication.ts @@ -1,6 +1,6 @@ -import { HTTPAuthentication } from './HTTPAuthentication' -import { RequestContext } from '../../../server/v2/RequestContext' import { ITestableUserManager } from '../userManager/ITestableUserManager' +import { HTTPAuthentication } from './HTTPAuthentication' +import { HTTPRequestContext } from '../../../server/v2/RequestContext' import { Errors } from '../../../Errors' import { IUser } from '../IUser' @@ -16,7 +16,7 @@ export class HTTPBasicAuthentication implements HTTPAuthentication } } - getUser(arg : RequestContext, callback : (error : Error, user : IUser) => void) + getUser(arg : HTTPRequestContext, callback : (error : Error, user : IUser) => void) { const onError = (error : Error) => { diff --git a/src/user/v2/authentication/HTTPDigestAuthentication.ts b/src/user/v2/authentication/HTTPDigestAuthentication.ts index aa24aa0c..12a4a11a 100644 --- a/src/user/v2/authentication/HTTPDigestAuthentication.ts +++ b/src/user/v2/authentication/HTTPDigestAuthentication.ts @@ -1,5 +1,5 @@ import { HTTPAuthentication } from './HTTPAuthentication' -import { RequestContext } from '../../../server/v2/RequestContext' +import { HTTPRequestContext } from '../../../server/v2/RequestContext' import { IListUserManager } from '../userManager/IListUserManager' import { Errors } from '../../../Errors' import { IUser } from '../IUser' @@ -31,7 +31,7 @@ export class HTTPDigestAuthentication implements HTTPAuthentication } } - getUser(arg : RequestContext, callback : (error : Error, user : IUser) => void) + getUser(arg : HTTPRequestContext, callback : (error : Error, user : IUser) => void) { const onError = (error : Error) => { diff --git a/src/user/v2/privilege/PrivilegeManager.ts b/src/user/v2/privilege/PrivilegeManager.ts index ce80cedb..263591e9 100644 --- a/src/user/v2/privilege/PrivilegeManager.ts +++ b/src/user/v2/privilege/PrivilegeManager.ts @@ -1,8 +1,4 @@ -import { RequestContext } from '../../../server/v2/RequestContext' import { Resource, Path } from '../../../manager/v2/export' -import { Lock } from '../../../resource/lock/Lock' -import { LockType } from '../../../resource/lock/LockType' -import { LockScope } from '../../../resource/lock/LockScope' import { Workflow } from '../../../helper/Workflow' export type PrivilegeManagerCallback = (error : Error, hasAccess : boolean) => void; diff --git a/src/user/v2/privilege/SimplePathPrivilegeManager.ts b/src/user/v2/privilege/SimplePathPrivilegeManager.ts index 47499a47..2be7212a 100644 --- a/src/user/v2/privilege/SimplePathPrivilegeManager.ts +++ b/src/user/v2/privilege/SimplePathPrivilegeManager.ts @@ -1,8 +1,7 @@ import { BasicPrivilege, PrivilegeManager, PrivilegeManagerCallback } from './PrivilegeManager' -import { RequestContext } from '../../../server/v2/RequestContext' import { Resource, Path } from '../../../manager/v2/export' -import { IUser } from '../IUser' import { Errors } from '../../../Errors' +import { IUser } from '../IUser' function standarizePath(path : string) { diff --git a/src/user/v2/simple/SimpleUserManager.ts b/src/user/v2/simple/SimpleUserManager.ts index 1c2f540f..fe56ed35 100644 --- a/src/user/v2/simple/SimpleUserManager.ts +++ b/src/user/v2/simple/SimpleUserManager.ts @@ -1,5 +1,5 @@ -import { IListUserManager } from '../userManager/IListUserManager' import { ITestableUserManager } from '../userManager/ITestableUserManager' +import { IListUserManager } from '../userManager/IListUserManager' import { SimpleUser } from './SimpleUser' import { Errors } from '../../../Errors' import { IUser } from '../IUser'