From 478145751afb3403ae3ddc7849b163ce5b2c8860 Mon Sep 17 00:00:00 2001 From: Adrien Castex Date: Tue, 13 Jun 2017 15:57:30 +0200 Subject: [PATCH] Added support to HTTPS --- lib/server/WebDAVServerOptions.d.ts | 4 +++- lib/server/WebDAVServerOptions.js | 3 ++- lib/server/webDAVServer/StartStop.js | 4 +++- lib/server/webDAVServer/WebDAVServer.d.ts | 3 ++- src/server/WebDAVServerOptions.ts | 4 +++- src/server/webDAVServer/StartStop.ts | 4 +++- src/server/webDAVServer/WebDAVServer.ts | 3 ++- 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/server/WebDAVServerOptions.d.ts b/lib/server/WebDAVServerOptions.d.ts index 19b5745b..761cfbed 100644 --- a/lib/server/WebDAVServerOptions.d.ts +++ b/lib/server/WebDAVServerOptions.d.ts @@ -4,6 +4,7 @@ import { IPrivilegeManager } from '../user/privilege/IPrivilegeManager'; import { IUserManager } from '../user/IUserManager'; import { IResource } from '../resource/IResource'; import { Writable } from 'stream'; +import * as https from 'https'; export declare class WebDAVServerOptions { requireAuthentification?: boolean; httpAuthentication?: HTTPAuthentication; @@ -11,10 +12,11 @@ export declare class WebDAVServerOptions { rootResource?: IResource; userManager?: IUserManager; lockTimeout?: number; + strictMode?: boolean; canChunk?: boolean; hostname?: string; + https?: https.ServerOptions; port?: number; - strictMode?: boolean; autoSave?: { treeFilePath: string; tempTreeFilePath: string; diff --git a/lib/server/WebDAVServerOptions.js b/lib/server/WebDAVServerOptions.js index 2d536778..aeb70b1a 100644 --- a/lib/server/WebDAVServerOptions.js +++ b/lib/server/WebDAVServerOptions.js @@ -12,10 +12,11 @@ var WebDAVServerOptions = (function () { this.rootResource = new RootResource_1.RootResource(); this.userManager = new SimpleUserManager_1.SimpleUserManager(); this.lockTimeout = 3600; + this.strictMode = false; this.canChunk = true; this.hostname = '::'; + this.https = null; this.port = 1900; - this.strictMode = false; this.autoSave = null; } return WebDAVServerOptions; diff --git a/lib/server/webDAVServer/StartStop.js b/lib/server/webDAVServer/StartStop.js index 2812819b..f3a9afdb 100644 --- a/lib/server/webDAVServer/StartStop.js +++ b/lib/server/webDAVServer/StartStop.js @@ -2,6 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var WebDAVRequest_1 = require("../WebDAVRequest"); var Errors_1 = require("../../Errors"); +var https = require("https"); var http = require("http"); var zlib = require("zlib"); var fs = require("fs"); @@ -101,7 +102,8 @@ function start(port, callback) { throw Errors_1.Errors.IllegalArguments; } if (!this.server) { - this.server = http.createServer(function (req, res) { + var serverCreator = this.options.https ? function (c) { return https.createServer(_this.options.https, c); } : function (c) { return http.createServer(c); }; + this.server = serverCreator(function (req, res) { var method = _this.methods[_this.normalizeMethodName(req.method)]; if (!method) method = _this.unknownMethod; diff --git a/lib/server/webDAVServer/WebDAVServer.d.ts b/lib/server/webDAVServer/WebDAVServer.d.ts index 2277b249..6ae81482 100644 --- a/lib/server/webDAVServer/WebDAVServer.d.ts +++ b/lib/server/webDAVServer/WebDAVServer.d.ts @@ -7,6 +7,7 @@ import { HTTPAuthentication } from '../../user/authentication/HTTPAuthentication import { IPrivilegeManager } from '../../user/privilege/IPrivilegeManager'; import { FSPath } from '../../manager/FSManager'; import { IUserManager } from '../../user/IUserManager'; +import * as https from 'https'; import * as http from 'http'; import * as persistence from './Persistence'; import * as beforeAfter from './BeforeAfter'; @@ -23,7 +24,7 @@ export declare class WebDAVServer { protected beforeManagers: WebDAVRequest[]; protected afterManagers: WebDAVRequest[]; protected unknownMethod: WebDAVRequest; - protected server: http.Server; + protected server: http.Server | https.Server; constructor(options?: WebDAVServerOptions); getResourceFromPath(path: FSPath | string[] | string, callback: ReturnCallback): any; getResourceFromPath(path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback): any; diff --git a/src/server/WebDAVServerOptions.ts b/src/server/WebDAVServerOptions.ts index bac80890..6c233bc6 100644 --- a/src/server/WebDAVServerOptions.ts +++ b/src/server/WebDAVServerOptions.ts @@ -8,6 +8,7 @@ import { RootResource } from '../resource/std/RootResource' import { IUserManager } from '../user/IUserManager' import { IResource } from '../resource/IResource' import { Writable } from 'stream' +import * as https from 'https' export class WebDAVServerOptions { @@ -17,10 +18,11 @@ export class WebDAVServerOptions rootResource ?: IResource = new RootResource() userManager ?: IUserManager = new SimpleUserManager() lockTimeout ?: number = 3600 + strictMode ?: boolean = false canChunk ?: boolean = true hostname ?: string = '::' + https ?: https.ServerOptions = null port ?: number = 1900 - strictMode ?: boolean = false autoSave ?: { treeFilePath : string tempTreeFilePath : string diff --git a/src/server/webDAVServer/StartStop.ts b/src/server/webDAVServer/StartStop.ts index 4725f7b7..edbc7bbf 100644 --- a/src/server/webDAVServer/StartStop.ts +++ b/src/server/webDAVServer/StartStop.ts @@ -3,6 +3,7 @@ import { WebDAVServerStartCallback } from './Types' import { Errors, HTTPError } from '../../Errors' import { WebDAVServer } from './WebDAVServer' import { Writable, Readable } from 'stream' +import * as https from 'https' import * as http from 'http' import * as zlib from 'zlib' import * as fs from 'fs' @@ -126,7 +127,8 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We if(!this.server) { - this.server = http.createServer((req : http.IncomingMessage, res : http.ServerResponse) => + const serverCreator = this.options.https ? (c) => https.createServer(this.options.https, c) : (c) => http.createServer(c); + this.server = serverCreator((req : http.IncomingMessage, res : http.ServerResponse) => { let method : WebDAVRequest = this.methods[this.normalizeMethodName(req.method)]; if(!method) diff --git a/src/server/webDAVServer/WebDAVServer.ts b/src/server/webDAVServer/WebDAVServer.ts index a61b1439..b05fe683 100644 --- a/src/server/webDAVServer/WebDAVServer.ts +++ b/src/server/webDAVServer/WebDAVServer.ts @@ -7,6 +7,7 @@ import { IPrivilegeManager } from '../../user/privilege/IPrivilegeManager' import { FSManager, FSPath } from '../../manager/FSManager' import { IUserManager } from '../../user/IUserManager' import Commands from '../commands/Commands' +import * as https from 'https' import * as http from 'http' import * as persistence from './Persistence' @@ -30,7 +31,7 @@ export class WebDAVServer protected beforeManagers : WebDAVRequest[] protected afterManagers : WebDAVRequest[] protected unknownMethod : WebDAVRequest - protected server : http.Server + protected server : http.Server | https.Server constructor(options ?: WebDAVServerOptions) {