UNPKG

@anglr/rest

Version:

Angular module representing rest services

40 lines 1.65 kB
import { isBlank, isPresent } from '@jscrpt/common'; /** * Middleware that is used for setting custom http headers */ export class HeadersMiddleware { //######################### public static properties ######################### /** * String identification of middleware */ static { this.id = 'HeadersMiddleware'; } //######################### public methods - implementation of RestMiddleware ######################### /** * Runs code that is defined for this rest middleware, in this method you can modify request and response * @param this - Method is bound to RESTClient * @param id - Unique id that identifies request method * @param target - Prototype of class that are decorators applied to * @param methodName - Name of method that is being modified * @param descriptor - Descriptor of method that is being modified * @param args - Array of arguments passed to called method * @param request - Http request that you can modify * @param next - Used for calling next middleware with modified request */ run(_id, _target, _methodName, descriptor, _args, request, next) { if (isBlank(descriptor.headers)) { return next(request); } const headers = {}; // set method specific headers for (const k in descriptor.headers) { if (isPresent(descriptor.headers[k])) { headers[k] = descriptor.headers[k]; } } request = request.clone({ setHeaders: headers }); return next(request); } } //# sourceMappingURL=headers.middleware.js.map