Giter VIP home page Giter VIP logo

Comments (12)

kanongil avatar kanongil commented on August 21, 2024

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.

tdukai avatar tdukai commented on August 21, 2024

Request headers does have the accept-encoding header with the values of: 'gzip, deflate, sdch'
image

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.

tdukai avatar tdukai commented on August 21, 2024

image

from inert.

kanongil avatar kanongil commented on August 21, 2024

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.

kanongil avatar kanongil commented on August 21, 2024

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.

tdukai avatar tdukai commented on August 21, 2024

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);

image

Then I added a console.log to the onPreResponse event

server.ext('onPreResponse', function (request, reply) {
    console.log(request.response.headers);
    return reply.continue();
});

image

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.

kanongil avatar kanongil commented on August 21, 2024

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.

tdukai avatar tdukai commented on August 21, 2024

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.

kanongil avatar kanongil commented on August 21, 2024

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.

kanongil avatar kanongil commented on August 21, 2024

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.

tdukai avatar tdukai commented on August 21, 2024

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.

lock avatar lock commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.