Differences
This shows you the differences between two versions of the page.
| tech-notes:browsers:pre-flight-requests [2025/02/18 09:02] – created gerardorourke | tech-notes:browsers:pre-flight-requests [2025/02/18 09:20] (current) – [Setting this in an apache .htaccess config - e.g. Access-Control-Max-Age: 600 # Caches for 10 minutes] gerardorourke | ||
|---|---|---|---|
| Line 46: | Line 46: | ||
| ====When Is a Preflight Request NOT Needed?==== | ====When Is a Preflight Request NOT Needed?==== | ||
| - | A preflight request is skipped if the request is " | + | A preflight request is skipped if the request is " |
| - | ✅ No custom headers (except Content-Type: | + | |
| - | ✅ No authentication credentials (cookies, Authorization header). | + | ✅ No custom headers (except Content-Type: |
| + | ✅ No authentication credentials (cookies, Authorization header). | ||
| Example of a simple request that does NOT trigger preflight: | Example of a simple request that does NOT trigger preflight: | ||
| < | < | ||
| Line 67: | Line 69: | ||
| http | http | ||
| Access-Control-Max-Age: | Access-Control-Max-Age: | ||
| + | </ | ||
| + | |||
| C. Move API Calls to the Same Origin | C. Move API Calls to the Same Origin | ||
| * If possible, use reverse proxies to avoid CORS altogether. | * If possible, use reverse proxies to avoid CORS altogether. | ||
| Line 72: | Line 76: | ||
| * Instead of Access-Control-Allow-Origin: | * Instead of Access-Control-Allow-Origin: | ||
| ________________________________________ | ________________________________________ | ||
| + | |||
| ==== Key Takeaways==== | ==== Key Takeaways==== | ||
| * Preflight requests use OPTIONS to check if the main request is allowed. | * Preflight requests use OPTIONS to check if the main request is allowed. | ||
| Line 79: | Line 84: | ||
| ________________________________________ | ________________________________________ | ||
| - | ===== Setting this in an apache .htaccess config | + | ===== apache .htaccess config ===== |
| + | < | ||
| < | < | ||
| Header set Access-Control-Allow-Origin " | Header set Access-Control-Allow-Origin " | ||
| Line 88: | Line 93: | ||
| Header set Access-Control-Max-Age " | Header set Access-Control-Max-Age " | ||
| </ | </ | ||
| + | </ | ||
| * Access-Control-Allow-Origin " | * Access-Control-Allow-Origin " | ||