feat: add additional supported interfaces

This includes the relevant auth headers and a simplification of several others.
This commit is contained in:
Joachim Van Herwegen
2020-05-25 11:05:04 +02:00
parent f8e136cadb
commit a4f2b3995c
12 changed files with 107 additions and 35 deletions

View File

@@ -1,22 +1,8 @@
import { IncomingMessage, ServerResponse } from 'http';
import { AsyncHandler } from '../util/AsyncHandler';
import { HttpRequest } from './HttpRequest';
import { HttpResponse } from './HttpResponse';
/**
* An HTTP request handler.
*/
export interface HttpHandler {
/**
* Checks whether this handler supports the given request.
* @param req - The input request.
*
* @returns A promise that indicates if this request is supported after resolving.
*/
canHandle: (req: Request) => Promise<boolean>;
/**
* Handles the given request.
* @param req - The input request.
* @param res - The response needed for responding to the request.
*
* @returns A promise resolving when the handling is finished.
*/
handle: (req: IncomingMessage, res: ServerResponse) => Promise<void>;
}
export type HttpHandler = AsyncHandler<{ request: HttpRequest; response: HttpResponse }>;

View File

@@ -0,0 +1,6 @@
import { IncomingMessage } from 'http';
/**
* An incoming HTTP request;
*/
export type HttpRequest = IncomingMessage;

View File

@@ -0,0 +1,6 @@
import { OutgoingMessage } from 'http';
/**
* An outgoing HTTP response;
*/
export type HttpResponse = OutgoingMessage;