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
最新推荐文章于 2021-03-11 21:52:44 发布