No9 / harmon

middleware for node-http-proxy to modify the remote website response with trumpet
Other
424 stars 62 forks source link

got error on zlib #52

Closed instkffff closed 4 years ago

instkffff commented 4 years ago

my code

const http = require('http')
const https = require('https')
const httpProxy = require('http-proxy')
const url = require('url')
const connect = require('connect')
const harmon = require('harmon')

selects = []
simpleselect = {}
simpleselect1 = {}

simpleselect.query = '[src*="jquery.min"]'
simpleselect1.query = '[src*="jquery-ui.min"]'

simpleselect.func = function(node) {
    node.setAttribute('src', 'http://libs.baidu.com/jquery/1.5.1/jquery.min.js')
}
simpleselect1.func = function(node) {
    node.setAttribute('src', 'http://libs.baidu.com/jqueryui/1.8.10/jquery-ui.min.js')
}

selects.push(simpleselect)
selects.push(simpleselect1)

finalUrl = 'https://evemaps.dotlan.net/'
parsedUrl = url.parse(finalUrl)

proxy = httpProxy.createProxyServer({
    target: finalUrl,
    agent: https.globalAgent,
    headers: {
        host: parsedUrl.hostname
    },
    prependPath: false,
    hostRewrite: finalUrl.host,
    protocolRewrite: parsedUrl.protocol,
    xfwd: true
})

const app = connect()

app.use(harmon([],selects))
app.use(function(req,res){
    proxy.web(req,res)
})

http.createServer(app).listen(8000)

error got

Error: unexpected end of file
    at Zlib.zlibOnError [as onerror] (zlib.js:170:17)
Emitted 'error' event on Gunzip instance at:
    at Zlib.zlibOnError [as onerror] (zlib.js:173:8) {
  errno: -5,
  code: 'Z_BUF_ERROR'
instkffff commented 4 years ago

solved with https://github.com/No9/harmon/pull/50