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

res.getHeader function does not exist #117

Closed
basickarl opened this issue Sep 22, 2016 · 8 comments
Closed

res.getHeader function does not exist #117

basickarl opened this issue Sep 22, 2016 · 8 comments
Assignees
Labels

Comments

@basickarl
Copy link

I'm wondering if this module is not up to date?

test.txt
/home/karl/dev/node/proto-buffer-api-karl/node_modules/lasso/node_modules/send/index.js:761
  if (!res.getHeader('Accept-Ranges')) res.setHeader('Accept-Ranges', 'bytes');
           ^

TypeError: res.getHeader is not a function
    at SendStream.setHeader (/home/karl/dev/node/proto-buffer-api-karl/node_modules/lasso/node_modules/send/index.js:761:12)
    at SendStream.send (/home/karl/dev/node/proto-buffer-api-karl/node_modules/lasso/node_modules/send/index.js:531:8)
    at onstat (/home/karl/dev/node/proto-buffer-api-karl/node_modules/lasso/node_modules/send/index.js:624:10)
    at FSReqWrap.oncomplete (fs.js:82:15)

Express uses the following to set headers: http://expressjs.com/en/4x/api.html
States: res.set('Content-Type', 'text/html');. Same goes for koajs.

Can't see any getHeader function either in expressjs nor koajs.

@dougwilson
Copy link
Contributor

dougwilson commented Sep 22, 2016

Express has .getHeader, as it comes from Node.js. Can you provide the following information?

  1. Version of Node.js you are using.
  2. Version of this module you are using.
  3. Complete code I can copy and paste and run to reproduce the issue.
  4. Instructions for how I can reproduce the issue.

Thank you!

@basickarl
Copy link
Author

basickarl commented Sep 22, 2016

@dougwilson

  1. Tried both v4.5.0 and v6.6.0
  2. ^0.13.0
    3 & 4:
  • git clone git@github.com:basickarl/send-error.git
  • cd send-error
  • npm install
  • node index
  • in the browser visit http://127.0.0.1:3000/static/test.txt

It's a module called lasso https://github.com/lasso-js/lasso which I'm trying to use. Itself uses send for it's middleware.

@basickarl
Copy link
Author

I replaced res.getHeader(... with just res.get(... and it seemed to work. Got another error though.

Fair enough nodejs does have it: https://nodejs.org/api/http.html#http_response_getheader_name
Express v4.x doesn't seem to have it: http://expressjs.com/en/api.html#res
Neither does Koajs: http://koajs.com/

@dougwilson
Copy link
Contributor

Ah, I see. The serveStatic export from lasso does not work with Koa, which is why you are getting that error. You need to file an issue to make serveStatic work with Koa on the lasso module.

Express v4.x doesn't seem to have it: http://expressjs.com/en/api.html#res

Not true; At the top of that section, it says:

The res object is an enhanced version of Node’s own response object and supports all built-in fields and methods.

And Node.js response object (linked to in those docs) has getHeader method.

Regardless, the issue is that you're not using lasso correctly, and the error that occurs in this module is just a symptom of that issue.

@dougwilson dougwilson self-assigned this Sep 22, 2016
@basickarl
Copy link
Author

basickarl commented Sep 22, 2016

@dougwilson Ah. I failed to mention that I have a pull request waiting for the lasso bug with koa: lasso-js/lasso#163

So it does work (with my fix). The next issue is Send now, which is why I started this issue.

So what your saying is that send does not support koa?

@dougwilson
Copy link
Contributor

So what your saying is that send does not support koa?

No, I'm saying that lasso didn't. send works just fine with Koa as long as you are actually passing in the correct objects to send. They way you were using it was not doing that. The code you showed me, you were passing the Koa context object to his module where you should have been passing in a request object and then you were passing in the Koa next function to this module where you should have been passing in the response object.

@basickarl
Copy link
Author

@dougwilson Ok gotcha! Just wanted your view on the whole thing!

@dougwilson
Copy link
Contributor

No problem, @basickarl I hope that all made sense :)

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

No branches or pull requests

2 participants