Skip to content

Commit

Permalink
Added support to HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrienCastex committed Jun 13, 2017
1 parent 8f346dd commit 4781457
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/server/WebDAVServerOptions.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ 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;
privilegeManager?: IPrivilegeManager;
rootResource?: IResource;
userManager?: IUserManager;
lockTimeout?: number;
strictMode?: boolean;
canChunk?: boolean;
hostname?: string;
https?: https.ServerOptions;
port?: number;
strictMode?: boolean;
autoSave?: {
treeFilePath: string;
tempTreeFilePath: string;
Expand Down
3 changes: 2 additions & 1 deletion lib/server/WebDAVServerOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/server/webDAVServer/StartStop.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion lib/server/webDAVServer/WebDAVServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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<IResource>): any;
getResourceFromPath(path: FSPath | string[] | string, rootResource: IResource, callback: ReturnCallback<IResource>): any;
Expand Down
4 changes: 3 additions & 1 deletion src/server/WebDAVServerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/server/webDAVServer/StartStop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/server/webDAVServer/WebDAVServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)
{
Expand Down

0 comments on commit 4781457

Please sign in to comment.