-
-
Notifications
You must be signed in to change notification settings - Fork 378
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: check existence of res.getHeader
and set the correct Content-Type
#385
fix: check existence of res.getHeader
and set the correct Content-Type
#385
Conversation
res.getHeader
res.getHeader
Codecov Report
@@ Coverage Diff @@
## master #385 +/- ##
=======================================
Coverage 96.96% 96.96%
=======================================
Files 7 7
Lines 264 264
=======================================
Hits 256 256
Misses 8 8
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #385 +/- ##
==========================================
+ Coverage 96.77% 96.86% +0.08%
==========================================
Files 12 13 +1
Lines 279 287 +8
Branches 81 83 +2
==========================================
+ Hits 270 278 +8
Misses 9 9
Continue to review full report at Codecov.
|
res.getHeader
res.getHeader
and set the correct Content-Type
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.
In any case, if we don't have res.getHeader
will be an error here so I think this change is no problem.
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.
We don't support webpack-serve
, it is deprecated and officially doesn't supporting, and we need tests
I strongly recommend migrate from |
@evilebottnawi But this issue is truly introduced by this package. Why not responsible for your upstream if you regard your package as the cornerstone? |
@ulivz upstream? As i said above |
Did you mean that I should write a test for KOA usage as https://github.com/webpack/webpack-dev-middleware/blob/master/test/tests/server.js |
@ulivz no, just defined (mock) |
@evilebottnawi Got it! |
I tried to add test under ref: https://github.com/expressjs/express/blob/master/lib/response.js#L784
So shouldn't I write a test for KOA usage? Here is my test case: describe.only('custom Content-Type when res.setHeader is undefined', () => {
before((done) => {
app = express();
app.use((req, res, next) => {
// Cover getHeader at the prototype.
res.getHeader = undefined;
res.set('Content-Type', 'application/octet-stream');
next();
});
const compiler = webpack(webpackConfig);
instance = middleware(compiler, {
stats: 'errors-only',
logLevel
});
app.use((req, res, next) => {
// Recover getHeader;
delete res.getHeader;
next();
});
listen = listenShorthand(done);
});
after(close);
it('Do not guess mime type if Content-Type header is found', (done) => {
request(app).get('/bundle.js')
.expect('Content-Type', 'application/octet-stream')
.expect(200, done);
});
}); |
Just mock value, no need import |
Writing a new test or still in |
@ulivz |
Sorry for my poor intimate knowledge of sinon,I just read the docs of sinon, it told me:
But for now we need to mock a Or, do you mean that I should mock the express? |
Yes, just mock |
@evilebottnawi Tests updated and passed, could you help re-review this MR? Thanks. This out of PR is very important to us. Thanks! |
Any progress here? |
@ulivz i was on vacation |
Thanks~ |
What kind of change does this PR introduce?
Bug fix
Did you add tests for your changes?
No tests needed.
Summary
This PR is tagged "bug fix" but actually a feature request.
I'm the maintainer of VuePress and recently we found a very influential issue(vuepress dev: throws res.getHeader() is not a function) but we cannot fix it by ourself. and it's introduced by b2a6fed. (But after careful investigation, I found that this is the legacy of history.)
This is due to VuePress@0.x depends on
webpack-serve@1.0.2
,webpack-serve
depends onkoa-webpack
, andkoa-webpack
doesn't lock the version ofwebpack-dev-middleware
:https://github.com/shellscape/koa-webpack/blob/0ea07dbd11f899f0e419808f2472b2d832d0d9c3/package.json#L24
The issue is already fixed in shellscape/koa-webpack#110 (released as v5.2.2) but we cannot enjoy this fix since
webpack-serve@1.0.2
depends onkoa-webpack@4.x
.One way to resolve the issue is to update
webpack-serve
dependency to 2.x.However,
webpack-serve
introduced breaking changes in v2 and we‘re not going to make any technological changes for VuePress@0.x because it's stable enough and we're also focused on 1.x.Since
webpack-serve
has been deprecated, the best way I can think of is to check the existence ofres.getHeader
atwebpack-dev-middleware
. Of course, all of this is because the author ofkoa-webpack
did not pass in thegetHeader
method in4.x
at that time:https://github.com/shellscape/koa-webpack/blob/v4.0.0/index.js#L48
I'll appreciate you if you accept this change, Thanks!
Does this PR introduce a breaking change?
No.
Other information