We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4a40d63 commit 20e58cfCopy full SHA for 20e58cf
5 files changed
lib/application.js
@@ -59,6 +59,8 @@ module.exports = class Application extends Emitter {
59
this.context = Object.create(context);
60
this.request = Object.create(request);
61
this.response = Object.create(response);
62
+ // util.inspect.custom support for node 6+
63
+ /* istanbul ignore else */
64
if (util.inspect.custom) {
65
this[util.inspect.custom] = this.inspect;
66
}
lib/response.js
@@ -572,11 +572,12 @@ module.exports = {
572
};
573
574
/**
575
- * Custom inspection implementation for newer Node.js versions.
+ * Custom inspection implementation for node 6+.
576
*
577
* @return {Object}
578
* @api public
579
*/
580
+/* istanbul ignore else */
581
582
module.exports[util.inspect.custom] = module.exports.inspect;
583
test/application/respond.js
@@ -683,6 +683,28 @@ describe('app.respond', () => {
683
.expect('Content-Type', 'application/json; charset=utf-8')
684
.expect('{"hello":"world"}');
685
});
686
+ describe('and headers sent', () => {
687
+ it('should respond with json body and headers', () => {
688
+ const app = new Koa();
689
+
690
+ app.use(ctx => {
691
+ ctx.length = 17;
692
+ ctx.type = 'json';
693
+ ctx.set('foo', 'bar');
694
+ ctx.res.flushHeaders();
695
+ ctx.body = { hello: 'world' };
696
+ });
697
698
+ const server = app.listen();
699
700
+ return request(server)
701
+ .get('/')
702
+ .expect('Content-Type', 'application/json; charset=utf-8')
703
+ .expect('Content-Length', '17')
704
+ .expect('foo', 'bar')
705
+ .expect('{"hello":"world"}');
706
707
708
709
710
describe('when an error occurs', () => {
test/response/length.js
@@ -5,23 +5,21 @@ const response = require('../helpers/context').response;
5
const assert = require('assert');
6
const fs = require('fs');
7
8
-describe('res.length', () => {
9
- describe('when Content-Length is defined', () => {
10
- it('should return a number', () => {
11
- const res = response();
12
- res.header['content-length'] = '120';
13
- assert.equal(res.length, 120);
14
- });
15
16
-});
17
-
18
describe('res.length', () => {
19
describe('when Content-Length is defined', () => {
20
it('should return a number', () => {
21
const res = response();
22
res.set('Content-Length', '1024');
23
assert.equal(res.length, 1024);
24
+ describe('but not number', () => {
+ it('should return 0', () => {
+ const res = response();
+ res.set('Content-Length', 'hey');
+ assert.equal(res.length, 0);
25
26
27
describe('when Content-Length is not defined', () => {
test/response/set.js
@@ -25,8 +25,8 @@ describe('ctx.set(name, val)', () => {
it('should set a field value of array', () => {
const ctx = context();
28
- ctx.set('x-foo', ['foo', 'bar']);
29
- assert.deepEqual(ctx.response.header['x-foo'], [ 'foo', 'bar' ]);
+ ctx.set('x-foo', ['foo', 'bar', 123 ]);
+ assert.deepEqual(ctx.response.header['x-foo'], [ 'foo', 'bar', '123' ]);
30
31
32
0 commit comments