Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core, common): add webdav http methods support #9465

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions packages/common/decorators/http/request-mapping.decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,69 @@ export const Options = createMappingDecorator(RequestMethod.OPTIONS);
*/
export const Head = createMappingDecorator(RequestMethod.HEAD);

/**
* Route handler (method) Decorator. Routes Webdav PROPFIND requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const PropFind = createMappingDecorator(RequestMethod.PROPFIND);

/**
* Route handler (method) Decorator. Routes Webdav PROPPATCH requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const PropPatch = createMappingDecorator(RequestMethod.PROPPATCH);

/**
* Route handler (method) Decorator. Routes Webdav MKCOL requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const MKCOL = createMappingDecorator(RequestMethod.MKCOL);

/**
* Route handler (method) Decorator. Routes Webdav COPY requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const Copy = createMappingDecorator(RequestMethod.COPY);

/**
* Route handler (method) Decorator. Routes Webdav MOVE requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const Move = createMappingDecorator(RequestMethod.MOVE);

/**
* Route handler (method) Decorator. Routes Webdav LOCK requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const Lock = createMappingDecorator(RequestMethod.LOCK);

/**
* Route handler (method) Decorator. Routes Webdav UNLOCK requests to the specified path.
*
* @see [Routing](https://docs.nestjs.com/controllers#routing)
*
* @publicApi
*/
export const Unlock = createMappingDecorator(RequestMethod.UNLOCK);

/**
* Route handler (method) Decorator. Routes all HTTP requests to the specified path.
*
Expand Down
5 changes: 5 additions & 0 deletions packages/common/enums/http-status.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ export enum HttpStatus {
NO_CONTENT = 204,
RESET_CONTENT = 205,
PARTIAL_CONTENT = 206,
MULTI_STATUS = 207,
ALREADY_REPORTED = 208,
AMBIGUOUS = 300,
MOVED_PERMANENTLY = 301,
FOUND = 302,
Expand Down Expand Up @@ -38,6 +40,7 @@ export enum HttpStatus {
I_AM_A_TEAPOT = 418,
MISDIRECTED = 421,
UNPROCESSABLE_ENTITY = 422,
LOCKED = 423,
FAILED_DEPENDENCY = 424,
PRECONDITION_REQUIRED = 428,
TOO_MANY_REQUESTS = 429,
Expand All @@ -47,4 +50,6 @@ export enum HttpStatus {
SERVICE_UNAVAILABLE = 503,
GATEWAY_TIMEOUT = 504,
HTTP_VERSION_NOT_SUPPORTED = 505,
INSUFFICIENT_STORAGE = 507,
LOOP_DETECTED = 508,
}
7 changes: 7 additions & 0 deletions packages/common/enums/request-method.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,11 @@ export enum RequestMethod {
ALL,
OPTIONS,
HEAD,
PROPFIND,
PROPPATCH,
MKCOL,
COPY,
MOVE,
LOCK,
UNLOCK,
}
14 changes: 14 additions & 0 deletions packages/common/interfaces/http/http-server.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ export interface HttpServer<TRequest = any, TResponse = any> {
put(path: string, handler: RequestHandler<TRequest, TResponse>): any;
patch(handler: RequestHandler<TRequest, TResponse>): any;
patch(path: string, handler: RequestHandler<TRequest, TResponse>): any;
propfind(handler: RequestHandler<TRequest, TResponse>): any;
propfind(path: string, handler: RequestHandler<TRequest, TResponse>): any;
proppatch(handler: RequestHandler<TRequest, TResponse>): any;
proppatch(path: string, handler: RequestHandler<TRequest, TResponse>): any;
mkcol(handler: RequestHandler<TRequest, TResponse>): any;
mkcol(path: string, handler: RequestHandler<TRequest, TResponse>): any;
copy(handler: RequestHandler<TRequest, TResponse>): any;
copy(path: string, handler: RequestHandler<TRequest, TResponse>): any;
move(handler: RequestHandler<TRequest, TResponse>): any;
move(path: string, handler: RequestHandler<TRequest, TResponse>): any;
lock(handler: RequestHandler<TRequest, TResponse>): any;
lock(path: string, handler: RequestHandler<TRequest, TResponse>): any;
unlock(handler: RequestHandler<TRequest, TResponse>): any;
unlock(path: string, handler: RequestHandler<TRequest, TResponse>): any;
all(path: string, handler: RequestHandler<TRequest, TResponse>): any;
all(handler: RequestHandler<TRequest, TResponse>): any;
options(handler: RequestHandler<TRequest, TResponse>): any;
Expand Down
42 changes: 42 additions & 0 deletions packages/core/adapters/http-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,48 @@ export abstract class AbstractHttpAdapter<
return this.instance.patch(...args);
}

public propfind(handler: RequestHandler);
public propfind(path: any, handler: RequestHandler);
public propfind(...args: any[]) {
return this.instance.propfind(...args);
}

public proppatch(handler: RequestHandler);
public proppatch(path: any, handler: RequestHandler);
public proppatch(...args: any[]) {
return this.instance.propfind(...args);
}

public mkcol(handler: RequestHandler);
public mkcol(path: any, handler: RequestHandler);
public mkcol(...args: any[]) {
return this.instance.propfind(...args);
}

public copy(handler: RequestHandler);
public copy(path: any, handler: RequestHandler);
public copy(...args: any[]) {
return this.instance.propfind(...args);
}

public move(handler: RequestHandler);
public move(path: any, handler: RequestHandler);
public move(...args: any[]) {
return this.instance.propfind(...args);
}

public lock(handler: RequestHandler);
public lock(path: any, handler: RequestHandler);
public lock(...args: any[]) {
return this.instance.propfind(...args);
}

public unlock(handler: RequestHandler);
public unlock(path: any, handler: RequestHandler);
public unlock(...args: any[]) {
return this.instance.propfind(...args);
}

public all(handler: RequestHandler);
public all(path: any, handler: RequestHandler);
public all(...args: any[]) {
Expand Down
14 changes: 14 additions & 0 deletions packages/core/helpers/router-method-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ export class RouterMethodFactory {
return target.head;
case RequestMethod.GET:
return target.get;
case RequestMethod.PROPFIND:
return target.propfind;
case RequestMethod.PROPPATCH:
return target.proppatch;
case RequestMethod.MKCOL:
return target.mkcol;
case RequestMethod.COPY:
return target.copy;
case RequestMethod.MOVE:
return target.move;
case RequestMethod.LOCK:
return target.lock;
case RequestMethod.UNLOCK:
return target.unlock;
default: {
return target.use;
}
Expand Down