proxy_request = http.request opt, (p_res) -> headers = p_res.headers statusCode = p_res.statusCode content_encoding = headers["content-encoding"] res.writeHead(statusCode, headers) bfh = new BufferHelper() p_res.on 'data', (chunk) -> bfh.concat(chunk) p_res.on 'end', () -> buffer = bfh.toBuffer() if buffer.length != 0 && content_encoding == "gzip" str = '' zlib.gunzip buffer, (err, gunzip) -> str = gunzip.toString() str = str.replace('<title>', '<title>test test') zlib.gzip new Buffer(str), (err, gzip) -> res.write(gzip) res.end() else res.write(buffer) if buffer.length != 0 res.end()
nodejs改写http
猜你喜欢
转载自fox1984.iteye.com/blog/1589113
今日推荐
周排行