Skip to content

Commit 4781457

Browse files
committed
Added support to HTTPS
1 parent 8f346dd commit 4781457

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

lib/server/WebDAVServerOptions.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ import { IPrivilegeManager } from '../user/privilege/IPrivilegeManager';
44
import { IUserManager } from '../user/IUserManager';
55
import { IResource } from '../resource/IResource';
66
import { Writable } from 'stream';
7+
import * as https from 'https';
78
export declare class WebDAVServerOptions {
89
requireAuthentification?: boolean;
910
httpAuthentication?: HTTPAuthentication;
1011
privilegeManager?: IPrivilegeManager;
1112
rootResource?: IResource;
1213
userManager?: IUserManager;
1314
lockTimeout?: number;
15+
strictMode?: boolean;
1416
canChunk?: boolean;
1517
hostname?: string;
18+
https?: https.ServerOptions;
1619
port?: number;
17-
strictMode?: boolean;
1820
autoSave?: {
1921
treeFilePath: string;
2022
tempTreeFilePath: string;

lib/server/WebDAVServerOptions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ var WebDAVServerOptions = (function () {
1212
this.rootResource = new RootResource_1.RootResource();
1313
this.userManager = new SimpleUserManager_1.SimpleUserManager();
1414
this.lockTimeout = 3600;
15+
this.strictMode = false;
1516
this.canChunk = true;
1617
this.hostname = '::';
18+
this.https = null;
1719
this.port = 1900;
18-
this.strictMode = false;
1920
this.autoSave = null;
2021
}
2122
return WebDAVServerOptions;

lib/server/webDAVServer/StartStop.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Object.defineProperty(exports, "__esModule", { value: true });
33
var WebDAVRequest_1 = require("../WebDAVRequest");
44
var Errors_1 = require("../../Errors");
5+
var https = require("https");
56
var http = require("http");
67
var zlib = require("zlib");
78
var fs = require("fs");
@@ -101,7 +102,8 @@ function start(port, callback) {
101102
throw Errors_1.Errors.IllegalArguments;
102103
}
103104
if (!this.server) {
104-
this.server = http.createServer(function (req, res) {
105+
var serverCreator = this.options.https ? function (c) { return https.createServer(_this.options.https, c); } : function (c) { return http.createServer(c); };
106+
this.server = serverCreator(function (req, res) {
105107
var method = _this.methods[_this.normalizeMethodName(req.method)];
106108
if (!method)
107109
method = _this.unknownMethod;

lib/server/webDAVServer/WebDAVServer.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { HTTPAuthentication } from '../../user/authentication/HTTPAuthentication
77
import { IPrivilegeManager } from '../../user/privilege/IPrivilegeManager';
88
import { FSPath } from '../../manager/FSManager';
99
import { IUserManager } from '../../user/IUserManager';
10+
import * as https from 'https';
1011
import * as http from 'http';
1112
import * as persistence from './Persistence';
1213
import * as beforeAfter from './BeforeAfter';
@@ -23,7 +24,7 @@ export declare class WebDAVServer {
2324
protected beforeManagers: WebDAVRequest[];
2425
protected afterManagers: WebDAVRequest[];
2526
protected unknownMethod: WebDAVRequest;
26-
protected server: http.Server;
27+
protected server: http.Server | https.Server;
2728
constructor(options?: WebDAVServerOptions);
2829
getResourceFromPath(path: FSPath | string[] | string, callback: ReturnCallback<IResource>): any;
2930
getResourceFromPath(path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback<IResource>): any;

src/server/WebDAVServerOptions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { RootResource } from '../resource/std/RootResource'
88
import { IUserManager } from '../user/IUserManager'
99
import { IResource } from '../resource/IResource'
1010
import { Writable } from 'stream'
11+
import * as https from 'https'
1112

1213
export class WebDAVServerOptions
1314
{
@@ -17,10 +18,11 @@ export class WebDAVServerOptions
1718
rootResource ?: IResource = new RootResource()
1819
userManager ?: IUserManager = new SimpleUserManager()
1920
lockTimeout ?: number = 3600
21+
strictMode ?: boolean = false
2022
canChunk ?: boolean = true
2123
hostname ?: string = '::'
24+
https ?: https.ServerOptions = null
2225
port ?: number = 1900
23-
strictMode ?: boolean = false
2426
autoSave ?: {
2527
treeFilePath : string
2628
tempTreeFilePath : string

src/server/webDAVServer/StartStop.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { WebDAVServerStartCallback } from './Types'
33
import { Errors, HTTPError } from '../../Errors'
44
import { WebDAVServer } from './WebDAVServer'
55
import { Writable, Readable } from 'stream'
6+
import * as https from 'https'
67
import * as http from 'http'
78
import * as zlib from 'zlib'
89
import * as fs from 'fs'
@@ -126,7 +127,8 @@ export function start(port ?: number | WebDAVServerStartCallback, callback ?: We
126127

127128
if(!this.server)
128129
{
129-
this.server = http.createServer((req : http.IncomingMessage, res : http.ServerResponse) =>
130+
const serverCreator = this.options.https ? (c) => https.createServer(this.options.https, c) : (c) => http.createServer(c);
131+
this.server = serverCreator((req : http.IncomingMessage, res : http.ServerResponse) =>
130132
{
131133
let method : WebDAVRequest = this.methods[this.normalizeMethodName(req.method)];
132134
if(!method)

src/server/webDAVServer/WebDAVServer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { IPrivilegeManager } from '../../user/privilege/IPrivilegeManager'
77
import { FSManager, FSPath } from '../../manager/FSManager'
88
import { IUserManager } from '../../user/IUserManager'
99
import Commands from '../commands/Commands'
10+
import * as https from 'https'
1011
import * as http from 'http'
1112

1213
import * as persistence from './Persistence'
@@ -30,7 +31,7 @@ export class WebDAVServer
3031
protected beforeManagers : WebDAVRequest[]
3132
protected afterManagers : WebDAVRequest[]
3233
protected unknownMethod : WebDAVRequest
33-
protected server : http.Server
34+
protected server : http.Server | https.Server
3435

3536
constructor(options ?: WebDAVServerOptions)
3637
{

0 commit comments

Comments
 (0)