question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't set headers for DELETE method

See original GitHub issue

I create an instance of axios: const api = axios.create({ baseURL: process.env.BASE_URL, timeout: 1000, });

I am able to set the header for POST: api.defaults.headers.post['X-CSRFToken'] = cookie.csrftoken;

However, if I try to set the header for DELETE: api.defaults.headers.delete['X-CSRFToken'] = cookie.csrftoken;

I get the following error: Cannot set property ‘X-CSRFToken’ of undefined

Is this expected behavior?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
moeinrahimicommented, Mar 6, 2018

in my case doing delete with axios in below method doesn’t send header.

       let {data} = await axios.delete(baseUrl+`/likepost`,
       {
         postId:postId
       },{headers:{Cookie:`sid=${cookie}`}})

but this way it’s working correctly

  let {data} = await axios({
        url:baseUrl+`/likepost`,
        method:'delete',
        data : {postId},
        headers:{Cookie:`sid=${cookie}`}
      })
2reactions
sajidkhakicommented, Sep 18, 2019

axios.delete({ url: ‘/system/ABC/delete/’ + selectedId, headers: {‘Authorization’: 'Bearer ’ + token}, withCredentials: true }).then(function (response) {…

i try to use csrf in delete , but i am getting this error in node.js

DELETE http://localhost:3131/system/ABC/delete/473TL095G3x-HpugwipBP0RAMmyer5cPDafrNg0 403 (Forbidden)

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to enable DELETE request? - Stack Overflow
I solved it without adding new packages, just added this line res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE");.
Read more >
Access-Control-Allow-Headers - HTTP - MDN Web Docs
The Access-Control-Allow-Headers response header is used in response to a preflight request which includes the ...
Read more >
Troubleshoot CORS errors from API Gateway - AWS
The following example procedure shows how to troubleshoot the No 'Access-Control-Allow-Origin' header present CORS error.
Read more >
Cannot set headers after they are sent to the client in JS
The "Cannot set headers after they are sent to the client" error occurs when the server in an express.js application sends more than...
Read more >
HTTP/1.1: Method Definitions
Although this set can be expanded, additional methods cannot be assumed to ... The Host request-header field (section 14.23) MUST accompany all HTTP/1.1 ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found