softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.89k stars 167 forks source link

Headers get lost when retrying #218

Open maxharlow opened 2 years ago

maxharlow commented 2 years ago

Retried requests seem to lose the configured headers. For example this:

import Axios from 'axios'
import AxiosRetry from 'axios-retry'

AxiosRetry(Axios)

Axios.interceptors.request.use(config => {
    console.log(config.headers)
    return config
})

Axios({
    url: 'http://httpstat.us/500',
    headers: {
        authorization: 'Basic example'
    }
})

Produces this output:

AxiosHeaders {
  authorization: 'Basic example',
  [Symbol(defaults)]: { Accept: 'application/json, text/plain, */*' }
}
AxiosHeaders {
  '[object Object]': undefined,
  [Symbol(defaults)]: { '0': [Function: get] }
}
node:internal/errors:477
    ErrorCaptureStackTrace(err);
    ^

TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["0"]
    at ClientRequest.setHeader (node:_http_outgoing:606:3)
    at new ClientRequest (node:_http_client:275:14)
    at Object.request (node:http:96:10)
    at RedirectableRequest._performRequest (/Users/maxharlow/Desktop/node_modules/follow-redirects/index.js:284:24)
    at new RedirectableRequest (/Users/maxharlow/Desktop/node_modules/follow-redirects/index.js:66:8)
    at Object.request (/Users/maxharlow/Desktop/node_modules/follow-redirects/index.js:523:14)
    at dispatchHttpRequest (file:///Users/maxharlow/Desktop/node_modules/axios/lib/adapters/http.js:371:21)
    at new Promise (<anonymous>)
    at httpAdapter (file:///Users/maxharlow/Desktop/node_modules/axios/lib/adapters/http.js:105:10)
    at Axios.dispatchRequest (file:///Users/maxharlow/Desktop/node_modules/axios/lib/core/dispatchRequest.js:46:10) {
  code: 'ERR_INVALID_CHAR'
}

So you can see the authorisation header has been lost on the retried request, replaced with '[object Object]': undefined.

I'm using Axios v1.1.3 and Axios Retry v3.3.1.

HpSurani1997 commented 1 year ago

I have also same issue with Axios v1.1.3. upgrade axios version to 1.2.0-alpha.1. it is work for me.

efortes commented 1 year ago

I had 1.1.2 and had to upgrade to 1.4.0 to make it work.