Skip to content

response.streamify assumes stream has attribute _readableState #2368

@Thomathan

Description

@Thomathan

If this attribute doesn't exist, it throws TypeError: Cannot read property 'objectMode' of undefined

It should check if _readableState exists before it checks for objectMode.

Below is the relevant function and the diff for the fix needed.

Hapi: 8.1.0
Node: 0.10.35
npm: 2.1.18
File: hapi/lib/response.js

internals.Response.prototype._streamify = function (source, next) {

    if (source instanceof Stream) {
        var stream = (source.socket || source);
        if (stream._readableState.objectMode) {
            return next(Boom.badImplementation('Cannot reply with stream in object mode'));
        }

        this._payload = source;
        return next();
    }

    // other code
}

Diff

    451c451
    <         if (stream._readableState.objectMode) {
    ---
    >         if (stream._readableState && stream._readableState.objectMode) {

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions