Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Not possible to transform headers per request

Đang mở
#82 0 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
50/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
api

Hướng nghiên cứu

Bắt đầu bằng cách lần theo quá trình tạo request thông qua hàm deepMerge nội bộ và entry point transformRequest, đồng thời so sánh cách đối tượng headers được tái sử dụng giữa các request. Xác minh hành vi bằng các request lặp lại sử dụng ví dụ transformRequest đã cho; được xem là hoàn tất khi các phép biến đổi header theo từng request không còn quan sát thấy các đột biến từ những request trước đó và workaround custom-fetch đã được tài liệu hóa vẫn không cần thiết.

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

Mô tả

bug

I'm using transformRequest to add custom header to the request before it is sent the following way:

const apiClient = redaxios.create({
  baseURL,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json; charset=utf-8',
  },
  transformRequest: [(data, headers) => {
      console.log(headers['Payload-Signature']); // <-- here I see header set for previous request
      
      if (data) headers['Payload-Signature'] = signRequestBody(data);
  }],
});

As show in code above headers object is shared between requests and because of that it is not possible to customise headers per requests before one is sent.

The reason is that internal deepMerge function doesn't create a copy of 'options.header' property.

Expected behaviour:
I would expect it is possible to safely transform headers per request or modify other request props.

As a workaround I define a custom fetch:

const apiClient = redaxios.create({
  baseURL,
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json; charset=utf-8',
  },
  fetch: (url, options) =>  fetch(url, {
    ...options,
    headers: {
      ...options.headers,
      'payload-signature': signRequestBody(options.body),
    },
  }),
});
Ngôn ngữ chính
JavaScript
Star
4.9k
Fork
104
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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 developit/redaxios

Tất cả issue của developit/redaxios

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.