Skip to content

Commit

Permalink
Create ContentTypeMiddleware.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhck authored Oct 1, 2020
1 parent f73a7fc commit b4848f7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/middlewares/ContentTypeMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {IMiddleware} from "../Stack";
import {IFetchRequest, IFetchResponse} from "./FetchMiddleware";

export class ContentTypeMiddleware implements IMiddleware<IFetchRequest, Promise<IFetchResponse<any>>> {
constructor(private contentType: string = "application/json") {
}

public process(options: IFetchRequest, next: (nextOptions: IFetchRequest) => Promise<IFetchResponse<any>>): Promise<IFetchResponse<any>> {
if (!options.headers) {
options.headers = {};
}
options.headers["content-type"] = this.contentType;
return next(options);
}
}

0 comments on commit b4848f7

Please sign in to comment.