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

Lack of working res.getHeaders() breaks res.json() and some middleware. Possible fix suggestion. #56

Open
dustinbolton opened this issue Nov 20, 2023 · 1 comment

Comments

@dustinbolton
Copy link

dustinbolton commented Nov 20, 2023

When trying to use PassPort sessions middleware app.runMiddleware() results in failure due to problems with getting headers. A similar problem was encountered in Issue #39 with a partial workaround.

Error seen:

node:_http_outgoing:721
  const entry = headers[StringPrototypeToLowerCase(name)];
                       ^
TypeError: Cannot read properties of undefined (reading 'set-cookie')
    at ServerResponse.getHeader (node:_http_outgoing:721:24)
    at setcookie (/node_modules/express-session/index.js:661:18)
    at ServerResponse.<anonymous> (/node_modules/express-session/index.js:243:7)
    at ServerResponse.writeHead (/node_modules/on-headers/index.js:35:16)
    at ServerResponse._implicitHeader (node:_http_server:338:8)
    at writetop (/node_modules/express-session/index.js:276:15)
    at ServerResponse.end (/node_modules/express-session/index.js:343:16)
    at allFailed (/node_modules/passport/lib/middleware/authenticate.js:177:11)
    at attempt (/node_modules/passport/lib/middleware/authenticate.js:183:28)
    at strategy.fail (/node_modules/passport/lib/middleware/authenticate.js:305:9)

References for above error:

Adding the following into createRes() seems to fix the issue while restoring the ability for res.getHeader() to work.

Proposed Solution (submitted in PR #57):

res.getHeader = function(name) {
    if ( 'undefined' !== typeof headers[name] ) {
      return headers[name];
    }
    return null; 
  };
dustinbolton added a commit to dustinbolton/node-run-middleware that referenced this issue Nov 20, 2023
@dustinbolton
Copy link
Author

@Aminadav Do you think this PR looks okay? Thanks!

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

1 participant