9

When interacting with API, the custom Header key always become lowercase. I'm use Fetch, Axios, XMLHttpRequest and Frisbee (javascript network library) but the key always lowercase

My snippet code like this (with fetch() method), The key I'm push is: 'Token-Api' but the server receive: 'token-api', so it's show the error 401. It's work with Postman:

 const request = 'https://abcxyz';
 fetch(request, {
   method: 'GET',
   headers: {
     'Content-Type': 'application/json',
     'Token-Api':'...abcxyz....'
   }
 }).then((response) => {
            log(abcxyz)
        })...

What do I need to do?

bkit4u
  • 505
  • 2
  • 5
  • 18

2 Answers2

14

you can read this post: Are HTTP headers case-sensitive?

According to RFC 2616, HTTP headers should be case-insensitive. So this is not the bug of the libraries you mention above. You should fix the server to treat Token-Api and token-api at the same way.

Harlan
  • 847
  • 5
  • 15
  • 3
    It may not be considered a bug, still the fact the headers are case-insentive does not mean anyone may feel free to change the case (to me, at least). I'm wondering if are the libs to manipulate the case or the browser(s). – MatteoSp Feb 06 '21 at 23:33
-4

You can actually solve this quite easily with another header:

sensitive: true

Vippy
  • 1,356
  • 3
  • 20
  • 30