Comments (12)
If you run your node.js application with this environment: DEBUG=compression
, it should print out what it's doing. For example, if it decides not to compress a response, it should note the reason.
from compression.
Most likely it's because the response is too small. Your options above have treshold: 1,
, but "threshold" is not spelled correctly, so that setting doesn't do anything and it's defaulting to 1KB still.
from compression.
I fixed that typo and get the same result. Chrome says the output is 10 KB of size.
This is what Chrome reports - might be more than what CURL did there.
—
Remote Address: 127.0.0.1: 8080
Request URL: http://localhost: 8080/
Request Method: GET
Status Code: 200 OK
Request Headersview source
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8
Accept-Encoding: gzip, deflate, sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control: max-age=0
Connection: keep-alive
Host: localhost:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36
Response Headersview source
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-type: text/html
Date: Wed, 14 Jan 2015 20: 13: 08 GMT
Expires: Thu, 19 Nov 1981 08: 52: 00 GMT
Pragma: no-cache
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Powered-By: PHP/5.5.14
X-Response-Time: 65.813ms
from compression.
Ok. The only real way to debug is to follow #30 (comment) above and set the DEBUG
environment variable and watch the output from your Node.js application, which will report why it didn't compress.
from compression.
The result:
Compression...
compression| no compression: not acceptable +0ms
15.01.14 21:28:06 200 GET / (Unknown - 42ms)
Dont mind the „Unknown“ in the GET status report; connect-logger is buggy it seems. I can’t quite tell what it is trying to tell me, though.
Am 14.01.2015 um 21:24 schrieb Douglas Christopher Wilson [email protected]:
Ok. The only real way to debug is to follow #30 (comment) #30 (comment) above and set the DEBUG environment variable and watch the output from your Node.js application, which will report why it didn't compress.
—
Reply to this email directly or view it on GitHub #30 (comment).
from compression.
I turned to look into the source, and found:
var method = accept.encoding(['gzip', 'deflate', 'identity'])
// negotiation failed
if (!method || method === 'identity') {
nocompress('not acceptable')
return
}
This confuses me. My browser clearly sends that it can accept GZIP compression; while the method
variable seems to be set right.
from compression.
It certainly could be a bug. Can you add a debug('%s with %o', method, req.headers)
in that if
block and paste me it's output? Also, let me know what version of this module you are using.
from compression.
Okay. I went further and researched my FCGI bridge; and my guess was good. It did take out some of the original headers. I have compensated it, and now both versions - modified for PHP - and original are inside. Here is what that looks like:
[ [ 'SCRIPT_FILENAME', '/Users/Ingwie/Work/BIRD3/app.php' ],
[ 'REMOTE_ADDR', '127.0.0.1' ],
[ 'QUERY_STRING', '' ],
[ 'REQUEST_METHOD', 'GET' ],
[ 'SCRIPT_NAME', '/app.php' ],
[ 'PATH_INFO', '' ],
[ 'DOCUMENT_URI', '/app.php' ],
[ 'REQUEST_URI', '/app.php' ],
[ 'DOCUMENT_ROOT', '/Users/Ingwie/Work/BIRD3' ],
[ 'PHP_SELF', '/app.php' ],
[ 'GATEWAY_PROTOCOL', 'CGI/1.1' ],
[ 'SERVER_SOFTWARE', 'node/v0.10.31' ],
[ 'HTTP_HOST', 'localhost:8080' ],
[ 'HTTP_CONNECTION', 'keep-alive' ],
[ 'HTTP_CACHE_CONTROL', 'max-age=0' ],
[ 'HTTP_ACCEPT',
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ],
[ 'HTTP_USER_AGENT',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' ],
[ 'HTTP_ACCEPT_ENCODING', 'gzip, deflate, sdch' ],
[ 'HTTP_ACCEPT_LANGUAGE',
'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4' ],
[ 'HTTP_COOKIE',
'lang=en; _ga=GA1.1.1345378658.1419115314; PHPSESSID=fqnnujetrfou2tl6athk1ekjp6; undefined; de2930129c03684c8ea4c64ab6aba5b5=f910049361b6fc0ec773c40f6df92b4394e0dcb1a%3A4%3A%7Bi%3A0%3Bs%3A1%3A%221%22%3Bi%3A1%3Bs%3A13%3A%22IngwiePhoenix%22%3Bi%3A2%3Bi%3A2592000%3Bi%3A3%3Ba%3A0%3A%7B%7D%7D' ],
[ 'host', 'localhost:8080' ],
[ 'connection', 'keep-alive' ],
[ 'cache-control', 'max-age=0' ],
[ 'accept',
'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8' ],
[ 'user-agent',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36' ],
[ 'accept-encoding', 'gzip, deflate, sdch' ],
[ 'accept-language', 'de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4' ],
[ 'cookie',
'lang=en; _ga=GA1.1.1345378658.1419115314; PHPSESSID=fqnnujetrfou2tl6athk1ekjp6; undefined; de2930129c03684c8ea4c64ab6aba5b5=f910049361b6fc0ec773c40f6df92b4394e0dcb1a%3A4%3A%7Bi%3A0%3Bs%3A1%3A%221%22%3Bi%3A1%3Bs%3A13%3A%22IngwiePhoenix%22%3Bi%3A2%3Bi%3A2592000%3Bi%3A3%3Ba%3A0%3A%7B%7D%7D' ] ]
That is req.headers
, by the way.
So you see, the accept-encoding
does reach the middleware - since this printing came from a console.log from inside it and just after the Accepts
object is made - but isn't recognized.
I must be using the latest NPM version, since I just installed it.
from compression.
Gotcha. If that if the data within your req.headers
, that's the problem: req.headers
in Node.js is an object, not an array of arrays. Something in your code is messing with req.headers
and it's not in the format from Node.js. This module requires that it gets a req
object that conforms to http://nodejs.org/api/http.html#http_http_incomingmessage (see http://nodejs.org/api/http.html#http_message_headers for what the req.headers
object must look like).
from compression.
Yeah, I know where it is, too. :)
https://github.com/IngwiePhoenix/connect-yii/blob/master/node-php.js#L259
This module is actually a fork that just has a few things changed. Looks like that the FastCGI parser wants the array-array structure, and won't give it away, either. Thanks for your help, now I can go and modify it till it works!
from compression.
Et voila. Updated the module and now i get a proepr gzip compression. :) This is so cool!
Thanks again for providing me with the help that led me to the fixes i needed to do!
from compression.
It was no problem :) I'm glad we figured it out!
from compression.
Related Issues (20)
- "drain" event listener leak when using res.once("drain"); can't use res.removeListener("drain") HOT 3
- compresssion doesn't work ,the vue.txt is 2m HOT 2
- Content-Type: application/json; charset=utf-8 No effect HOT 2
- Question: Why this middleware HOT 2
- Corrupted compressed .js-files for Mac OS / Safari -clients HOT 11
- Is compression working when node server is running on a container? HOT 2
- middleware fails when the request has more than 1 values for accept-encoding header HOT 2
- Is compression result cached? HOT 1
- change Transfer-encoding HOT 1
- Why does the data size increase after compression HOT 1
- Force size to be a minimum... HOT 2
- Chunked encoding is broken after using this middleware HOT 1
- Using a current debug version HOT 1
- Deflate backwards HOT 7
- Compression instrumentation (before/after compression hooks) HOT 2
- Angular Not Compressing? HOT 2
- compression not working json payload HOT 6
- Crash when compressing characters like ū HOT 1
- Express returns a non-compliant HTTP/206 response when gzip is enabled HOT 9
- Reviving this package (1.8.0) HOT 1
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 compression.