Resolving Digest Auth challenge in middleware using events?

Đang mở
#1,648 1 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
25/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

Hướng nghiên cứu

Bắt đầu với lệnh gọi generalProxy.web và các API sự kiện proxyRes và proxyReq được mô tả trong issue. Xác định cách challenge Digest 401, URL đích ban đầu, việc thử lại request và MJPEG streaming được cung cấp trong suốt vòng đời của proxy. Kết quả cần là một phương pháp được hỗ trợ và có tài liệu, hoặc một yêu cầu tính năng có phạm vi rõ ràng.

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

Mô tả

I'm using http-proxy to make the MJPEG streams from some internal systems (IP cameras) available on a web portal, which only has port 80 available to access the backend. This works pretty well with this code.

  const generalProxy = httpProxy.createProxyServer()

  app.use('/proxy/:url', (req, res) => {
    // Example URL: http://localhost:8000/proxy/http%3A%2F%2F192.168.140.21%2Fmjpg%2Fvideo.mjpg%3Fresolution%3D80x80
    const { url } = req.params
    if (!url || typeof url !== 'string') {
      res.status(406).send('Missing URL')
      return
    }
    generalProxy.web(req, res, { target: url })
  }

However, now I need to target a service that requires Digest Auth, using a client which does not support Digest Auth. Disabling Digest Auth or using Basic Auth on the IP cameras is not an option, unfortunately.

I have been looking at the proxyRes and proxyReq middleware events, and think that I might be able to do something like this:

if target responds with 401:
  get Digest Auth header from response
  use a Digest Auth module to resolve the Digest challenge, with credentials from environment.
  repeat the original request, but with the Digest resolution added to the header
  proxy the response back to the client. 

However, I'm uncertain on how to proceed from here.

I tried to make a generalProxy.on('proxyRes', (proxyRes, req, res) => {....} where I check for (proxyRes.statusCode === 401) which indicates that a digest challenge might be received. However, I can't find the original target URL in an obvious way, since the proxyRequest object is not provided an argument here.

Also, I'm a little in doubt here, about how I should proceed with forwarding the MJPEG response back to the client, I was thinking something like `stream.on('data', (data)=>res.write(data) but I'm not sure if this is the way to go, and how to obtain the connection to the stream on the middle of a proxy event handler.

Any help will be appreciated

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.