-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix issue with sendOptions.maxAge being overwritten #24
Conversation
@ceecko: if you add a test for this, we can merge it. |
@XhmikosR I have added tests and a new option |
@@ -173,7 +177,7 @@ describe('.serve', () => { | |||
|
|||
it('should serve files without a hash tag', done => { | |||
http.get('http://localhost:12321/index.js', res => { | |||
res.headers['cache-control'].includes('max-age=0').should.be.true(); | |||
res.headers['cache-control'].includes('max-age=7200').should.be.true(); |
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.
I'd still like to have a test for max-age=0
, which is the default.
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.
The tests on lines 97 and 136 already check max-age=0
This test suite is meant to check custom max-age
for non-hashed assets
Also, please fetch upstream and rebase. :) |
That's a merge not a rebase BTW. So it's unmergeable. |
|
Yeah, sorry. Messed up a bit. |
Thanks, I'm gonna have a look tomorrow. |
sendOptions: opts.sendOptions || {} | ||
}; | ||
|
||
defaultOptions = Object.assign(defaultOptions, opts); | ||
|
||
defaultOptions.sendOptions.root = root; |
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.
Can't we move these 2 into setOptions
?
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.
Yep, makes sense
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.
I still feel like the following assignments aren't all needed.
We just have one options Object. Can't you put the new options there and just base your logic on maxAge
?
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.
If there was only one options object, the logic in serve
would have to change maxAge
for non-hashed assets and after calling send
reset maxAge
back to original value which may be confusing and introduces unnecessary overhead with every call.
The reason for this pull request is to resolve issues with a single options object's maxAge
being overwritten when a non-hashed asset is requested. Such call resets maxAge
to 0
and all subsequent requests started to use MAX_AGE
.
This fix resolves issue with
sendOptions.maxAge
being overwritten when 404 is returned.The following scenario resets the maxAge property:
sendOptions
)0
)0
andMAX_AGE
is used instead)