grunt-contrib-connect icon indicating copy to clipboard operation
grunt-contrib-connect copied to clipboard

Chinese garbage problem

Open chaoren1641 opened this issue 11 years ago • 11 comments

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!

chaoren1641 avatar Mar 28 '14 09:03 chaoren1641

锟斤拷问题很烦人啊,咋没人回呢?

chaoren1641 avatar Mar 31 '14 02:03 chaoren1641

We are gonna look into this. If you figure out how to ungarble your page before us, let us know.

vladikoff avatar Mar 31 '14 02:03 vladikoff

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 avatar Dec 09 '14 09:12 jasonslyvia

@jasonslyvia thank you : )

chaoren1641 avatar Dec 10 '14 01:12 chaoren1641

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?

jaymes-bearden avatar Feb 13 '15 03:02 jaymes-bearden

I have the same issue same issue with proxying to a site with charset=iso-8859-1 ( Icelandic ).

agirorn avatar Apr 15 '15 10:04 agirorn

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?

legendtang avatar Aug 05 '15 05:08 legendtang

It seems this is still a problem. Or has it been solved?

LukeSkyw avatar Jun 24 '16 08:06 LukeSkyw

Issue still exists and shouldn't be closed.

legendtang avatar Jun 24 '16 13:06 legendtang

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.

chaoren1641 avatar Jun 27 '16 05:06 chaoren1641