Resolving Digest Auth challenge in middleware using events?

Aperta
#1,648 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript, node.js
Ambito
backend

Direzione di ricerca

Inizia dalla chiamata generalProxy.web e dalle API degli eventi proxyRes e proxyReq descritte nell’issue. Determina come vengono esposti una challenge Digest 401, l’URL di destinazione originale, il nuovo tentativo della richiesta e lo streaming MJPEG durante il ciclo di vita del proxy. Il risultato dovrebbe essere un approccio supportato e documentato oppure una richiesta di funzionalità chiaramente delimitata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
JavaScript
Stelle
14.1k
Fork
2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di http-party/node-http-proxy

Tutte le issue di http-party/node-http-proxy

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.