grunt-contrib-connect
grunt-contrib-connect copied to clipboard
Chinese garbage problem
Hi,
I am a china's front-end developer。my web page encoding is gbk,But grunt-contrib-connect output encoding is utf-8:
Connection:keep-alive
content-length:3457
Content-Type:text/html; charset=UTF-8
so, my page becomes garbled.I know there may be is connect npm's problem,but I do not know how to solve。
I hope to get help here, thank you!
锟斤拷问题很烦人啊,咋没人回呢?
We are gonna look into this. If you figure out how to ungarble your page before us, let us know.
using middleware seems useless in this case
middleware: function(connect, options) {
return [
function(req, res, next) {
res.setHeader('Content-Type', 'text/html; charset=gbk');
return next();
},
connect.static(require('path').resolve('.'))
];
}
@jasonslyvia thank you : )
I'm having the same issue with files being proxied from middleware and grunt-connect is changing the character encoding. Images transferred through grunt-connect are effectively doubled in size.
Transferring without the middleware works fine.
Any suggested work arounds?
I have the same issue same issue with proxying to a site with charset=iso-8859-1 ( Icelandic ).
UPDATED 15.08.05 Sorry for last broken answer.
Try this, work for me. I am on v0.11.2
middleware: function(connect, options, middlewares) {
middlewares.unshift( function(req, res, next) {
if( /\s*.html/.test(req.url) ) {
res.setHeader('Content-Type', 'text/html; charset=gbk');
}
return next();
});
return middlewares;
},
Better not try to set global headers or you would mess up in other static files with 'text/html'. Also res.setHeader('Content-Type', 'charset=gbk'); only works on Firefox for me while Chrome and Safari seemed to respect this as 'Content-Type: text/html; charset=gbk by default.
I think this should be implemented into an option. As a basic server, encoding support is needed. What about your ideas?
It seems this is still a problem. Or has it been solved?
Issue still exists and shouldn't be closed.
This problem arises in 2 years ago, when a suitable opportunity to all pages change to UTF-8 is able to solve the garbage problem. And I don't have to grunt for a long time, so close it, if the problem still exists, then I re open it.