mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix spdy proxy (#962)
Signed-off-by: Jari Kolehmainen <jari.kolehmainen@gmail.com>
This commit is contained in:
parent
5b6b19036d
commit
d20f890ddb
@ -44,9 +44,7 @@ export class LensProxy {
|
|||||||
const spdyProxy = spdy.createServer({
|
const spdyProxy = spdy.createServer({
|
||||||
spdy: {
|
spdy: {
|
||||||
plain: true,
|
plain: true,
|
||||||
connection: {
|
protocols: ["http/1.1", "spdy/3.1"]
|
||||||
autoSpdy31: true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, (req: http.IncomingMessage, res: http.ServerResponse) => {
|
}, (req: http.IncomingMessage, res: http.ServerResponse) => {
|
||||||
this.handleRequest(proxy, req, res)
|
this.handleRequest(proxy, req, res)
|
||||||
@ -73,12 +71,40 @@ export class LensProxy {
|
|||||||
if (cluster) {
|
if (cluster) {
|
||||||
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "")
|
const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "")
|
||||||
const apiUrl = url.parse(cluster.apiUrl)
|
const apiUrl = url.parse(cluster.apiUrl)
|
||||||
const res = new http.ServerResponse(req)
|
const pUrl = url.parse(proxyUrl)
|
||||||
res.assignSocket(socket)
|
const connectOpts = { port: parseInt(pUrl.port), host: pUrl.hostname }
|
||||||
res.setHeader("Location", proxyUrl)
|
const proxySocket = new net.Socket()
|
||||||
res.setHeader("Host", apiUrl.hostname)
|
proxySocket.connect(connectOpts, () => {
|
||||||
res.statusCode = 302
|
proxySocket.write(`${req.method} ${pUrl.path} HTTP/1.1\r\n`)
|
||||||
res.end()
|
proxySocket.write(`Host: ${apiUrl.host}\r\n`)
|
||||||
|
for (let i = 0; i < req.rawHeaders.length; i += 2) {
|
||||||
|
const key = req.rawHeaders[i]
|
||||||
|
if (key !== "Host" && key !== "Authorization") {
|
||||||
|
proxySocket.write(`${req.rawHeaders[i]}: ${req.rawHeaders[i+1]}\r\n`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
proxySocket.write("\r\n")
|
||||||
|
proxySocket.write(head)
|
||||||
|
})
|
||||||
|
proxySocket.on('data', function (chunk) {
|
||||||
|
socket.write(chunk)
|
||||||
|
})
|
||||||
|
proxySocket.on('end', function () {
|
||||||
|
socket.end()
|
||||||
|
})
|
||||||
|
proxySocket.on('error', function (err) {
|
||||||
|
socket.write("HTTP/" + req.httpVersion + " 500 Connection error\r\n\r\n");
|
||||||
|
socket.end()
|
||||||
|
})
|
||||||
|
socket.on('data', function (chunk) {
|
||||||
|
proxySocket.write(chunk)
|
||||||
|
})
|
||||||
|
socket.on('end', function () {
|
||||||
|
proxySocket.end()
|
||||||
|
})
|
||||||
|
socket.on('error', function () {
|
||||||
|
proxySocket.end()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user