N
N
Nadim Zakirov2021-07-18 10:52:09
JavaScript
Nadim Zakirov, 2021-07-18 10:52:09

Why doesn't XMLHttpRequest.getAllResponseHeaders() show my own custom headers?

Let's say I knock on the server and the server in its response sends me a custom header:
Abra-Kadabra: 543467868998

But I simply don't see this header through XMLHttpRequest.getAllResponseHeaders!

Perhaps the problem is that the server address and the address from which the request is sent are different? If suddenly yes, how would it win? Is it possible to somehow tell on the server side that I allow any headers to be processed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gennady S, 2021-07-18
@zkrvndm

Not all headers are available from scripts in case of different domains / cross-origin, to control this there is a special header Access-Control-Expose-Headers , You need to send 'Access-Control-Expose-Headers' from the server with 'Abra-Kadabra'

T
TheOnlyFastCoder2, 2021-07-18
@TheOnlyFastCoder2

Because getAllResponseHeaders() displays the headers of the recipient, which gives you access to the request.
Here's the clarification from the documentation:


XMLHttpRequest.getAllResponseHeaders()
The XMLHttpRequest getAllResponseHeaders() method returns all CRLF-separated response headers as a string, or returns null if no response was received. If a network error occurs, an empty string is returned.


60f3f52fc51c5007978695.png

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question