Skip to content

Commit

Permalink
Default stream to application/octet-stream. Closes #3891
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Jan 6, 2019
1 parent c5da1b3 commit c88bda0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ exports = module.exports = internals.Response = class {
}
else if (source instanceof Stream) {
this.variety = 'stream';
this._contentType = 'application/octet-stream';
}

this.source = source;
Expand Down
29 changes: 27 additions & 2 deletions test/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ describe('Response', () => {
expect(res.result).to.equal(null);
expect(res.payload).to.equal('');
});

it('returns a stream', async () => {

const handler = (request) => {

const stream = new Stream.Readable({
read() {

this.push('x');
this.push(null);
}
});

return stream;
};

const server = Hapi.server();
server.route({ method: 'GET', path: '/', handler });

const res = await server.inject('/');
expect(res.result).to.equal('x');
expect(res.statusCode).to.equal(200);
expect(res.headers['content-type']).to.equal('application/octet-stream');
});
});

describe('code()', () => {
Expand Down Expand Up @@ -208,7 +232,7 @@ describe('Response', () => {

describe('created()', () => {

it('returns a stream response (created)', async () => {
it('returns a response (created)', async () => {

const handler = (request, h) => {

Expand Down Expand Up @@ -498,7 +522,7 @@ describe('Response', () => {

super();
this.statusCode = 299;
this.headers = { xcustom: 'some value' };
this.headers = { xcustom: 'some value', 'content-type': 'something/special' };
}

_read(size) {
Expand Down Expand Up @@ -526,6 +550,7 @@ describe('Response', () => {
expect(res.result).to.equal('x');
expect(res.statusCode).to.equal(299);
expect(res.headers.xcustom).to.equal('some value');
expect(res.headers['content-type']).to.equal('something/special');
});

it('excludes connection header and connection options', async () => {
Expand Down

0 comments on commit c88bda0

Please sign in to comment.