代码之家  ›  专栏  ›  技术社区  ›  jAndy

Nodejs代理脚本,不使用mod\u deflate

  •  3
  • jAndy  · 技术社区  · 15 年前

    我创建了一个代理节点脚本请求.url 或者将请求传递给我的apache服务器,或者使用node 一切正常,但当我 mod\ U放气 对于阿帕奇来说,

    看起来node只是“取消”或“停止”了对early的响应方式。 我在听我请求的“数据”事件 节点只是决定响应已经结束(这是错误的),并且

    var apache = http.createClient(82, 'localhost');
    
    function pass_to_apache(req, res){
        var request = apache.request(req.method, req.url, req.headers);
    
        req.addListener('end', function() {
            request.end();
        });
    
        req.addListener('data', function(chunk) {
            request.write(chunk);
            sys.puts('writting chunk\n');
        });
    
        request.addListener('response', function(response) {
            res.writeHead(response.statusCode, response.headers);
            response.addListener('data', function(chunk) {
                sys.puts('writting data..\n');
                res.write(chunk);
            });
            response.addListener('end', function() {
                sys.puts('end of request');
                res.end();
            });
        });
    }
    
    var MainServer = http.createServer(function(request, response) {
        sys.puts('received '+request.method+' '+request.url + "\n"+JSON.stringify(request.headers));
        if(/^\/node/.test(request.url)) {
            response.writeHead(200, {'Content-Type': 'text/plain'});
            response.end("Hi, it's node =)\n");
        }
        else if(/^\/exit/.test(request.url)) {
            sys.puts('closing..\n');
            MainServer.close();
            throw new Error('forced');
        }
        else {
            pass_to_apache(request, response);
        }
    });
    
    MainServer.listen(80, 'typeofnan.com');
    

    你可以在 www.typeofnan.com && www.typeofnan.com/node/anything
    暂时禁用nodejs。

    记住,如果没有gzip/deflate被 阿帕奇。我试图在我的回复中将编码设置为“二进制”,但没有

    我正在使用最新的relase(0.2.0)。

    有没有其他(更好的)解决方案来使用这样的proxyscript?

    1 回复  |  直到 15 年前
        1
  •  0
  •   bxjx    15 年前

    {"date":"Mon, 13 Sep 2010 11:03:45 GMT","server":"Apache/2.3.8 (Unix) mod_ssl/2.3.8 OpenSSL/1.0.0a","last-modified":"Sat, 11 Sep 2010 19:38:09 GMT","etag":"\"c9489a-4ada-4900100c32a40-gzip\"","accept-ranges":"bytes","vary":"Accept-Encoding","content-encoding":"gzip","cache-control":"max-age=86400","expires":"Tue, 14 Sep 2010 11:03:45 GMT","content-length":"5359","keep-alive":"timeout=5, max=100","connection":"Keep-Alive","content-type":"text/html"}
    

    六羟甲基三聚氰胺六甲醚。。。我是不是很幸运,没有得到引起你的问题的gzipped回复?你有一个页面,可靠地导致“奇怪的事情发生”,我可以测试?实际上,您可能需要定义“事情会发生”:

    接受编码 这样apache就不会返回压缩响应。向apache请求中添加以下内容将强制apache返回未压缩的响应:

    req.headers['accept-encoding'] = '*;q=1,gzip=0';
    
    推荐文章