remove asJson header restriction

This commit is contained in:
Joao Moreno
2018-01-29 17:54:38 +01:00
parent 2996b94e3c
commit 9702675d43

View File

@@ -165,13 +165,15 @@ export function asJson<T>(context: IRequestContext): TPromise<T> {
return c(null);
}
if (!/application\/json/.test(context.res.headers['content-type'])) {
return e('Response doesn\'t appear to be JSON');
}
const buffer: string[] = [];
context.stream.on('data', (d: string) => buffer.push(d));
context.stream.on('end', () => c(JSON.parse(buffer.join(''))));
context.stream.on('end', () => {
try {
c(JSON.parse(buffer.join('')));
} catch (err) {
e(err);
}
});
context.stream.on('error', e);
});
}