0
0
Expressframework~5 mins

Preflight requests behavior in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a preflight request in the context of CORS?
A preflight request is an HTTP OPTIONS request sent by the browser before the actual request. It checks if the server allows the real request with specific methods and headers.
Click to reveal answer
beginner
Which HTTP method is used for preflight requests?
The HTTP OPTIONS method is used for preflight requests to ask the server about allowed methods and headers.
Click to reveal answer
intermediate
How does Express handle preflight requests by default?
Express does not handle preflight requests automatically. You need to add middleware like 'cors' to respond properly to OPTIONS requests.
Click to reveal answer
intermediate
What headers are important in a preflight request and response?
Important headers include 'Access-Control-Request-Method' and 'Access-Control-Request-Headers' in the request, and 'Access-Control-Allow-Methods' and 'Access-Control-Allow-Headers' in the response.
Click to reveal answer
beginner
Why is handling preflight requests important in Express apps?
Handling preflight requests ensures browsers can verify permissions before sending actual requests, preventing CORS errors and enabling cross-origin communication.
Click to reveal answer
Which HTTP method does the browser use to send a preflight request?
AOPTIONS
BGET
CPOST
DPUT
In Express, what middleware is commonly used to handle CORS and preflight requests?
Aexpress-session
Bbody-parser
Ccors
Dhelmet
Which header does the browser send to specify the HTTP method it wants to use in the actual request during preflight?
AAccess-Control-Expose-Headers
BAccess-Control-Allow-Methods
CAccess-Control-Allow-Origin
DAccess-Control-Request-Method
What should the server include in the response to a preflight request to allow a POST method?
AAccess-Control-Allow-Methods: POST
BAccess-Control-Allow-Origin: POST
CAccess-Control-Request-Method: POST
DAccess-Control-Allow-Headers: POST
If an Express app does not handle preflight requests, what will happen when a browser sends a cross-origin request with custom headers?
AThe request will succeed without issues
BThe browser will block the request due to CORS error
CThe server will automatically respond with CORS headers
DThe browser will ignore CORS and send the request
Explain what a preflight request is and why it is important in Express applications.
Think about how browsers ask servers if they can send certain requests.
You got /4 concepts.
    Describe the key headers involved in preflight requests and responses.
    Focus on headers that specify methods and headers allowed.
    You got /4 concepts.