10 Tweets Nov 05, 2022
HTTP headers for CORS explained.
A thread πŸ§΅πŸ‘‡
Let's start with HTTP request headers:
πŸ“Œ Origin
The browser adds this header to CORS requests to indicate the origin domain.
πŸ“Œ Access-Control-Request-Method
Specific CORS requests that affect user data will initiate with a preflight request. This header is added to the preflight to indicate the method used in the main request. For example:
Access-Control-Request-Method: PUT
πŸ“Œ Access-Control-Request-Headers
This header is used when issuing a preflight request.
It is sent by the browser and defines the different HTTP headers the actual request might contain.
The server answers in a corresponding β€˜Access-Control-Allow-Headers’ response header.
Now let's move on to HTTP response headers:
πŸ“Œ Access-Control-Allow-Origin
This header defines the domain from which requests are accepted. If the value for this header is an asterisk(*), it indicates requests from any domain are accepted.
πŸ“Œ Access-Control-Allow-Credentials
This header is used in preflight requests to indicate whether a request can be made with credentials (cookies, TLS client certificates, or authorization headers). Its only valid value is β€˜true.’
πŸ“Œ Access-Control-Max-Age
This header is used to state how long the results of a preflight request can be cached in seconds.
πŸ“Œ Access-Control-Allow-Methods
This method defines one or more methods allowed to access the cross-origin resource and is sent in response to a preflight request. For example:
Access-Control-Allow-Methods: POST, OPTIONS
πŸ“Œ Access-Control-Allow-Headers
Used in response to a preflight request that contains β€˜Access-Control-Request-Headers.’ It indicates which HTTP headers can be used in the actual request.
We hope you liked this thread!
Follow @Rapid_API for more of our exclusive content. πŸ™πŸš€

Loading suggestions...