refactor
This commit is contained in:
parent
4e44c1c49e
commit
74cb04e7c1
1 changed files with 3 additions and 6 deletions
|
@ -168,6 +168,7 @@ function *respond(next) {
|
||||||
|
|
||||||
yield *next;
|
yield *next;
|
||||||
|
|
||||||
|
// allow bypassing koa
|
||||||
if (false === this.respond) return;
|
if (false === this.respond) return;
|
||||||
|
|
||||||
var res = this.res;
|
var res = this.res;
|
||||||
|
@ -188,21 +189,17 @@ function *respond(next) {
|
||||||
return res.end();
|
return res.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// status body
|
||||||
if (null == body) {
|
if (null == body) {
|
||||||
// status body
|
|
||||||
this.type = 'text';
|
this.type = 'text';
|
||||||
body = status[code];
|
body = status[code];
|
||||||
if (body) this.length = Buffer.byteLength(body);
|
if (body) this.length = Buffer.byteLength(body);
|
||||||
return res.end(body);
|
return res.end(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Buffer body
|
// responses
|
||||||
if (Buffer.isBuffer(body)) return res.end(body);
|
if (Buffer.isBuffer(body)) return res.end(body);
|
||||||
|
|
||||||
// string body
|
|
||||||
if ('string' == typeof body) return res.end(body);
|
if ('string' == typeof body) return res.end(body);
|
||||||
|
|
||||||
// Stream body
|
|
||||||
if (body instanceof Stream) return body.pipe(res);
|
if (body instanceof Stream) return body.pipe(res);
|
||||||
|
|
||||||
// body: json
|
// body: json
|
||||||
|
|
Loading…
Reference in a new issue