Skip to content

fix(request): return URL origin instead of Origin header#1971

Closed
xxiaoxiong wants to merge 1 commit into
koajs:masterfrom
xxiaoxiong:fix/request-origin-url-1958
Closed

fix(request): return URL origin instead of Origin header#1971
xxiaoxiong wants to merge 1 commit into
koajs:masterfrom
xxiaoxiong:fix/request-origin-url-1958

Conversation

@xxiaoxiong

Copy link
Copy Markdown

Fixes #1958

Why
ctx.origin in Koa 3 returns the value of the HTTP Origin request header (via req.headers.origin), which is null for direct browser requests. The expected behavior is to return the URL origin (e.g. http://127.0.0.1:3000), consistent with Koa 2 and the URL.origin specification.

Changes
Changed get origin() in lib/request.js to return this.protocol + :// + this.host instead of this.req.headers.origin || null.

Updated component: lib/request.js

Surface area

  • Request
  • Bug fix

@jonathanong

Copy link
Copy Markdown
Member

see original issue

additionally, when making PRs, please make sure you write tests.

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

Successfully merging this pull request may close these issues.

[fix] Missing Headers in Koa 3 vs 2 ( or update docs? )

2 participants