-
Notifications
You must be signed in to change notification settings - Fork 82
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
Keep headers after an error #11
Conversation
Oops, forgot we have to test for node 0.12, where |
537f9f2
to
7f4a517
Compare
This feature should be another middleware I think. |
Ok, I see this just want to set cors headers only on error. This should be ok. And now we should think about performance. Don't bind set function every request. set(this, key, value) will be better. And don't try catch if show header option is false. |
7f4a517
to
feaa797
Compare
Is this good? The set function still has to be local because it needs a local copy of |
@@ -49,6 +50,8 @@ module.exports = function (options) { | |||
|
|||
options.credentials = !!options.credentials; | |||
|
|||
options.headersKeptOnError = options.headersKeptOnError === undefined || !!options.headersKeptOnError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be keepHeadersOnError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this was from when I was planning on making it an array so you could only keep some. Will be fixed in just a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
feaa797
to
26afb4e
Compare
} else { | ||
// Preflight Request | ||
|
||
// If there is no Access-Control-Request-Method header or if parsing failed, | ||
// do not set any additional headers and terminate this set of steps. | ||
// The request is outside the scope of this specification. | ||
if (!this.get('Access-Control-Request-Method')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on Preflight Request
, there is won't throw any error on old code logic https://github.com/koajs/cors/blob/master/index.js#L88.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah I guess it won't have set any headers. Reverting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, that should simplify the diff quite a bit.
26afb4e
to
d532de3
Compare
+1 |
1.2.0 release. @PlasmaPower please pick this feature into v2.x branch |
If this is merged I'll rewrite it for v2.x.