Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/extend/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const proto = module.exports = {
* @param {Object} [options] - options for request.
* @return {Object} see {@link ContextHttpClient#curl}
*/
* curl(url, options) {
return yield this.httpclient.curl(url, options);
curl(url, options) {
return this.httpclient.curl(url, options);
},

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/core/context_httpclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class ContextHttpClient {
* @param {Object} [options] - options for request.
* @return {Object} see {@link Application#curl}
*/
* curl(url, options) {
curl(url, options) {
options = options || {};
options.ctx = this.ctx;
return yield this.app.curl(url, options);
return this.app.curl(url, options);
}

* request(url, options) {
return yield this.curl(url, options);
request(url, options) {
return this.curl(url, options);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/egg.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class EggApplication extends EggCore {
* console.log(result.status, result.headers, result.data);
* ```
*/
* curl(url, opts) {
return yield this.httpclient.request(url, opts);
curl(url, opts) {
return this.httpclient.request(url, opts);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions test/app/extend/context.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ describe('test/app/extend/context.test.js', () => {
const res = yield context.curl(`${localServer}/foo/bar`);
res.status.should.equal(200);
});

it('should curl as promise ok', () => {
return utils.startLocalServer()
.then(localServer => app.mockContext().curl(`${localServer}/foo/bar`))
.then(res => res.status.should.equal(200));
});
});

describe('ctx.httpclient', () => {
Expand Down