Resolving Digest Auth challenge in middleware using events?

オープン
#1,648 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, node.js
領域
backend

調査の方向性

Issue に記載されている generalProxy.web 呼び出しと proxyRes および proxyReq イベント API から始めます。401 Digest チャレンジ、元のターゲット URL、リクエストの再試行、MJPEG ストリーミングがプロキシのライフサイクル全体でどのように公開されるかを確認します。完了条件は、文書化されたサポート対象のアプローチ、または明確に範囲を定めた機能リクエストのいずれかとします。

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
JavaScript
スター
14.1k
フォーク
2k
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

http-party/node-http-proxy のほかの issue

http-party/node-http-proxy の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。