Koa: req.origin should display the `origin` header if it exists, not the current hostname

Created on 23 Jun 2017  路  11Comments  路  Source: koajs/koa

version-major

Most helpful comment

Don't agree with return header.origin when exist, else return protocol + host, For header.origin is mostly used for CORS. I think should return header.origindirectly.

All 11 comments

origin header should use request.get('origin') better than request.origin.

I think this would be a good change, request.origin isn't used by us for this reason. I think most plugins/users behind a proxy in need of origin get it via request.get anyway. E.g. https://github.com/koajs/cors/blob/master/index.js#L46

If this is done (thus semver-major bump), maybe consider other #904, and dropping https://github.com/koajs/koa/blob/master/lib/application.js#L107?

@jonathanong if you'd like to proceed with a new version, maybe create a v3 milestone as "todos"?

edit oh, the milestone already existed!

馃憤

What's the expected behaviour here?

if header.origin:
  return header.origin
else
  return this.protocol + this.host // current behaviour

Don't agree with return header.origin when exist, else return protocol + host, For header.origin is mostly used for CORS. I think should return header.origindirectly.

origin should reflect exactly-and-only what exists in the request. Special casing the behavior will be confusing and unexpected, especially when proxies/load balancers/VPNs start getting involved.

Yeah, it was very confusing to me, had to fallback to request.get('origin')

So let me try to understand that. If I want to compose links in my response, that the client can directly follow I have to use the origin header? Is it always guaranteed to be set?

why i use baseURl 127.0.0.1:port/xxxxxxxx in ssr get data, get hostname is { localhost: port } just equal the url ..........

Don't agree with return header.origin when exist, else return protocol + host, For header.origin is mostly used for CORS. I think should return header.origindirectly.

I agree. origin just should indicate where a fetch originates from. Not the host to which the request is being sent.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rally25rs picture rally25rs  路  4Comments

imkimchi picture imkimchi  路  4Comments

usernameisalreadytaken2014 picture usernameisalreadytaken2014  路  4Comments

rainesinternationaldev picture rainesinternationaldev  路  5Comments

ke1Del picture ke1Del  路  3Comments