implement IRequestFunction with xhr

This commit is contained in:
Johannes Rieken
2016-11-29 11:38:42 +01:00
parent 092718c5c3
commit a0658d5d69
4 changed files with 112 additions and 9 deletions

View File

@@ -31,11 +31,19 @@ export interface IRequestOptions {
}
export interface IRequestContext {
req: http.ClientRequest;
res: http.ClientResponse;
// req: http.ClientRequest;
// res: http.ClientResponse;
res: {
headers: { [n: string]: string };
statusCode?: number;
};
stream: Stream;
}
export interface IRequestFunction {
(options: IRequestOptions): TPromise<IRequestContext>;
}
export function request(options: IRequestOptions): TPromise<IRequestContext> {
let req: http.ClientRequest;
@@ -71,7 +79,7 @@ export function request(options: IRequestOptions): TPromise<IRequestContext> {
stream = stream.pipe(createGunzip());
}
c({ req, res, stream });
c({ res, stream });
}
});
@@ -144,4 +152,4 @@ export function asJson<T>(context: IRequestContext): TPromise<T> {
context.stream.on('end', () => c(JSON.parse(buffer.join(''))));
context.stream.on('error', e);
});
}
}