Intercept websocket request before proxying it to server via http-proxy

Đang mở
#1,624 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
20/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, node.js
Lĩnh vực
backend, networking

Hướng nghiên cứu

Bắt đầu bằng cách đọc luồng websocket xung quanh server.on('upgrade'), proxy.ws() và sự kiện proxyReqWs được nêu trong issue, sau đó so sánh với luồng REST-proxyReq. Công việc được xem là hoàn tất khi có một cách rõ ràng, được ghi lại trong tài liệu để truy cập dữ liệu xác thực websocket trước khi proxy kết nối và định tuyến kết nối đến instance đã chọn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Here is my code for proxying the websocket request to the targer server. What I want to achieve is that like in case of REST requests in http-proxy, we use proxyReq event to modify the request if we want by accessing headers and req.body, I want to do the same for weboscket request as I want to access the authentication data auth that is passed from the socket client. I don't want to log or intercept the traffic sent or received after the weboscket connection, instead I want to intercept (not modify though) the actual request that contains data to authenticate the client on proxyReqws event or on upgrade event of server. Any help & guidance would be appreciated.

var app = express();
const fs = require('fs')
var https = require('https')
var httpProxy = require('http-proxy');
const credentials = { key: fs.readFileSync("localhost.key"), cert: fs.readFileSync("localhost.cert") };

var proxy = httpProxy.createProxyServer({ ws: true });
var server = https.createServer(credentials, app).listen(8080)

proxy.on('proxyReqWs', (proxyReq, req, socket, options, head) => {
    //before the request is actually proxyed to the target server
    //access websocket request & modify it
});

app.use('/socket.io', function (req, res) {
    proxy.on('proxyRes', function (proxyRes, req, res) {
     //on response, do something
    });
    proxy.on('error', function (err, req, res) {
        console.log(err)
    })
    proxy.web(req, res, { target: { host: address.host, port: address.port, path: '/socket.io' } })

})

server.on('upgrade', function (req, socket, head) {
    console.log("Upgraded to websockets")
    proxy.ws(req, socket, head, { target: { host: address.host, port: address.port, path: '/socket.io' } });
});

On the basis of information I get from auth, the request will be routed to the specific instance.

Ngôn ngữ chính
JavaScript
Star
14.1k
Fork
2k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của http-party/node-http-proxy

Tất cả issue của http-party/node-http-proxy

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.