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

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

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

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
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 lần theo handler proxy.on("proxyRes") và lệnh gọi retry proxy.web() được nêu trong issue, bao gồm onResponseInterceptor và beforeRetry. Xác định lý do việc gọi proxy.web() sau một 401 không tạo ra response thứ hai; được xem là hoàn tất khi request có thể làm mới token, retry và expose response tiếp theo.

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

Mô tả

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?

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.