Comments (12)
The response will only contain the gzipped file if the request has specified that gzip is ok using the accept-encoding
header. Is this the case?
from inert.
Request headers does have the accept-encoding header with the values of: 'gzip, deflate, sdch'
I traced the code and until file.js internals.marshal method still had everything correct. All the necessary input was OK and seemingly grabbed the gz file, it set the proper header values etc... Once returned to the directory.js File.load(...) then it was gone and only the minified file got served back.
from inert.
from inert.
Well that sounds like a bug. Unfortunately I am unable to replicate it.
Which versions of node, hapi & inert are you using?
Are you using any specific server
or connection
options? Or registering other plugins?
from inert.
Actually, given that you are on Windows, this issue is likely caused by your anti-virus software, which will have modified the response before serving it to the browser.
Can you disable any such software and test again?
from inert.
Versions:
node: 5.0.0
inert: 3.2.0
hapi: 11.1.2
I added console.log(...) into this part of the code: (internals.marshal)
response.bytes(stat.size);
response.header('content-encoding', 'gzip');
response.vary('accept-encoding');
console.log(response.headers);
return internals.openStream(response, gzFile, next);
Then I added a console.log to the onPreResponse event
server.ext('onPreResponse', function (request, reply) {
console.log(request.response.headers);
return reply.continue();
});
It shows what I am seeing in the browser. I disabled my anti-virus but I do not really see how can cause anything while the code running inside hapi framework.
Oh almost forgot:
connection info:
server.connection({
port: process.env.PORT,
host: process.env.IP,
labels: ['site', 'saas'],
router: {
stripTrailingSlash: true
},
routes: {
cors: true,
validate: {
options: {
allowUnknown: true
}
}
}
});
plugins:
plugins.push({
register: require('hapi-swagger'),
options: {
documentationPath: '/restricted/docs',
apiVersion: pkg.version
}
});
Using dust.js (linkedin) for view engine but that would not impact how a static resource called from the rendered HTML would be found and served out.
That is all...
from inert.
The onPreResponse
is as intended – The marshal phase happens after the onPreResponse
hook, and before it knows that there exists a gzipped version of the file.
I still think the culprit is some local firewall (or maybe a chrome extension), which modifies the response.
from inert.
I do not think so that it has to do with firewall or chrome extension because I am running the app locally and I tried with Firefox + Firebug with the same results. I tried to use fiddler also which is very clearly shows that no compression is applied. I tried to modify the directory event handler into multiple file handlers:
{
method: "GET",
path: "/styles/{filename}",
config: {
description: "Serve css styles",
handler: function (request, reply) {
return reply.file(path.join('public/css', request.params.filename), { lookupCompressed: true });
},
tags: ['assets']
}
},
{
method: "GET",
path: "/scripts/{filename}",
config: {
description: "Serve js scripts",
handler: function (request, reply) {
return reply.file(path.join('public/js', request.params.filename), { lookupCompressed: true });
},
tags: ['assets']
}
},
This does not work either!
Is there any point I could check the response headers before it sent back? Something better then the onPreResponse hook? I want to prove that where exactly this happening...
from inert.
There is no such hook. If you want to check the headers, as it it passed onto node itself, you can grab them in hapi itself here: https://github.com/hapijs/hapi/blob/v11.1.4/lib/transmit.js#L286.
from inert.
Also, please don't use the reply.file()
method without parameter validation. The ones you linked can allow access to any file on your server.
from inert.
Thanks for pointing me to the hapi.js line. It was very useful. It seems like the proper size and header information set with the expected gzip-ed result. I think you right, it might be caused by something else. (OS or anti-virus software) I will be setting up a virtual box with Linux and checking it again. As for the validation of course I will have it setup. This was just a quick way to check the results. Thanks for noting though! :)
from inert.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
from inert.
Related Issues (20)
- Action required: Greenkeeper could not be activated 🚨 HOT 1
- Update joi HOT 1
- I'm upgrading hapi from v16 to v17 and trying to register plugins but getting error as- AssertionError [ERR_ASSERTION]: Invalid plugin options HOT 1
- Problem with serving static file HOT 1
- Only node 12
- Require hapi 19
- Change plugin name to @hapi/inert
- 6.0.1 should be 7.0.0 because it required hapi 19 whereas 6.0.0 does not HOT 4
- @hapi/ammo - Denial of Service HOT 1
- Directory listings fail with a 500 when path is absolute HOT 1
- `redirectToSlash` not being applied HOT 2
- Add an option to prevent following symlinks HOT 6
- Allow path functions to be async HOT 10
- Add h.directory() toolkit decoration HOT 2
- Disabling `must-revalidate` when serving static files via Inert HOT 1
- Invalid "inert" server options issue after Hapi update to 20.2.2 : HOT 5
- Release Notes 7.0.0 HOT 3
- SVG files being served as text/plain instead of image/svg, how do I fix this?
- Error: Failed to open file: ENAMETOOLONG HOT 1
- Unit Tests are failing for @hapi/[email protected] HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inert.