Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'Set-Cookie' of undefined #8

Open
paulb777 opened this issue Sep 23, 2011 · 4 comments
Open

TypeError: Cannot read property 'Set-Cookie' of undefined #8

paulb777 opened this issue Sep 23, 2011 · 4 comments

Comments

@paulb777
Copy link

If I add sesh to the download example from http://stackoverflow.com/questions/7288814/download-file-from-nodejs-server, I get the error below.

The following insertion to the first line of response.js's writeHead function seems to fix the problem:
headers = headers || {};

/Users/paulb/mds110804/node_modules/sesh/node_modules/response/lib/response.js:14
headers[k] = headers[k] || that._additionalHeaders[k];
^
TypeError: Cannot read property 'Set-Cookie' of undefined
at /Users/paulb/mds110804/node_modules/sesh/node_modules/response/lib/response.js:14:33
at Array.forEach (native)
at ServerResponse.writeHead
(/Users/paulb//mds110804/node_modules/sesh/node_modules/response/lib/response.js:13:46)
at ServerResponse._implicitHeader (http.js:797:8)
at ServerResponse.end (http.js:654:10)
at /Users/paulb/mds110804/server/download.js:33:17

@Marak
Copy link
Owner

Marak commented Sep 23, 2011

So, I'm pretty sure the additions I made for response are now part of node.js core.

I think this library needs to be updated to use the new core API.

@maciek134
Copy link

Found a fix, but I don't know if this will not break up whole script, because I just removed the
require('response')
line in core.js. Now it's working with node-static but like I said - I don't used this like that for much time, only for couple minutes. And I think require('eyes') is not needed anymore? Or I just have some antique release ;)

@paulb777
Copy link
Author

Making sure that headers is initialized on entry to response.js has been working for me.

@mike-aungsan
Copy link

I am having the same error now on node v0.10.24

@ sesh/node_modules/response/lib/response.js:14

headers is undefined. so line 15 is wrong.

headers[k] = headers[k] || that._additionalHeaders[k];

Change to the following work.

var tmp_headers = {};

if(headers !== undefined) {
  var tmp_headers = headers;
}

if (this._additionalHeaders) {
    Object.keys(this._additionalHeaders).forEach(function (k) {

        //headers[k] = headers[k] || that._additionalHeaders[k];

        tmp_headers[k] = tmp_headers[k] || that._additionalHeaders[k];

    });
}

_writeHead.call(this, status, tmp_headers);

Does anyone think it might break other somewhere ???

Best Regards,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants