if the proxyRes with bad statusCode, how can i retry the proxyRequest.

Aperta
#1,630 0 commenti 5 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript, node.js

Direzione di ricerca

Inizia tracciando l’handler proxy.on("proxyRes") e la chiamata di retry proxy.web() mostrati nella issue, inclusi onResponseInterceptor e beforeRetry. Determina perché invocare proxy.web() dopo un 401 non produce una seconda response; il lavoro è completato quando la richiesta può aggiornare il proprio token, eseguire un retry ed esporre la response successiva.

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

Descrizione

I want to automatically bring the token when the statusCode is 401 and re-request。
for example:

onResponseInterceptor: (proxyRes, req, res, retry) => {
        if (proxyRes.statusCode == 401) {
            retry()
        }
}

and the retry function is defined by:

  this.proxy.on("proxyRes", (proxyRes, req, res) => {
      console.log(req.headers);
      const retry = async () => {
          await this.option.beforeRetry?.(proxyRes, req, res)
          const retry = (req.headers['x-retry'] || '0') as string;
          req.headers["x-retry"] = (Number(retry) + 1).toString()
          this.proxy.web(req, res,{
              target: this.option.target,
              changeOrigin: true,
              selfHandleResponse: true
          })
      }
      this.option.onResponseInterceptor?.(proxyRes, req, res, retry)
  })

I tried to re-launch proxy.web() in proxy.on("proxyRes"). But this doesn't work and no second response is received. How do I solve this problem?

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.