| 3 | import "whatwg-fetch"; |
| 4 | |
| 5 | export class IsomorphicFetchHttpLibrary implements HttpLibrary { |
| 6 | |
| 7 | public send(request: RequestContext): Observable<ResponseContext> { |
| 8 | let method = request.getHttpMethod().toString(); |
| 9 | let body = request.getBody(); |
| 10 | |
| 11 | const resultPromise = fetch(request.getUrl(), { |
| 12 | method: method, |
| 13 | body: body as any, |
| 14 | headers: request.getHeaders(), |
| 15 | credentials: "same-origin" |
| 16 | }).then((resp: any) => { |
| 17 | const headers: { [name: string]: string } = {}; |
| 18 | resp.headers.forEach((value: string, name: string) => { |
| 19 | headers[name] = value; |
| 20 | }); |
| 21 | |
| 22 | const body = { |
| 23 | text: () => resp.text(), |
| 24 | binary: () => resp.blob() |
| 25 | }; |
| 26 | return new ResponseContext(resp.status, headers, body); |
| 27 | }); |
| 28 | |
| 29 | return from<Promise<ResponseContext>>(resultPromise); |
| 30 | |
| 31 | } |
| 32 | } |
nothing calls this directly
no outgoing calls
no test coverage detected