diff --git a/src/main/lens-proxy.ts b/src/main/lens-proxy.ts index 9801f776d0..dbd4f90c9e 100644 --- a/src/main/lens-proxy.ts +++ b/src/main/lens-proxy.ts @@ -44,9 +44,7 @@ export class LensProxy { const spdyProxy = spdy.createServer({ spdy: { plain: true, - connection: { - autoSpdy31: true - } + protocols: ["http/1.1", "spdy/3.1"] } }, (req: http.IncomingMessage, res: http.ServerResponse) => { this.handleRequest(proxy, req, res) @@ -73,12 +71,40 @@ export class LensProxy { if (cluster) { const proxyUrl = await cluster.contextHandler.resolveAuthProxyUrl() + req.url.replace(apiKubePrefix, "") const apiUrl = url.parse(cluster.apiUrl) - const res = new http.ServerResponse(req) - res.assignSocket(socket) - res.setHeader("Location", proxyUrl) - res.setHeader("Host", apiUrl.hostname) - res.statusCode = 302 - res.end() + const pUrl = url.parse(proxyUrl) + const connectOpts = { port: parseInt(pUrl.port), host: pUrl.hostname } + const proxySocket = new net.Socket() + proxySocket.connect(connectOpts, () => { + proxySocket.write(`${req.method} ${pUrl.path} HTTP/1.1\r\n`) + 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() + }) } }