mirror of
https://github.com/eggjs/egg.git
synced 2024-12-04 07:14:30 +00:00
27 lines
668 B
JavaScript
27 lines
668 B
JavaScript
class ContextHttpClient {
|
|
constructor(ctx) {
|
|
this.ctx = ctx;
|
|
this.app = ctx.app;
|
|
}
|
|
|
|
/**
|
|
* http request helper base on {@link HttpClient}, it will auto save httpclient log.
|
|
* Keep the same api with {@link Application#curl}.
|
|
*
|
|
* @param {String|Object} url - request url address.
|
|
* @param {Object} [options] - options for request.
|
|
* @return {Object} see {@link Application#curl}
|
|
*/
|
|
async curl(url, options) {
|
|
options = options || {};
|
|
options.ctx = this.ctx;
|
|
return await this.app.curl(url, options);
|
|
}
|
|
|
|
async request(url, options) {
|
|
return await this.curl(url, options);
|
|
}
|
|
}
|
|
|
|
module.exports = ContextHttpClient;
|