Add option to set request mode for fetch API
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 12.4k
- Forks
- 2.4k
- PR merge metrics
- No merged PRs in 30d
Description
Motivation
It is not strictly necessary in most cases, but if I know I only use URLs from the same-origin it can be better to use mode: 'same-security' for fetch requests to block cross origin requests altogether.
It isn't strictly necessary but it could be used to avoid accidentally calling CORS URLs
Implementation
In https://github.com/mapbox/mapbox-gl-js/blob/v3.24.0/src/util/ajax.ts#L118 add an option to also provide mode similar to cache mode etc.
See also https://developer.mozilla.org/en-US/docs/Web/API/Request/mode and https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#mode
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/util/ajax.ts around line 118 and compare the existing request options with the Fetch RequestInit mode documentation linked in the issue. Done means callers can provide a request mode and same-origin-only requests can prevent cross-origin fetches; verify the behavior with the project's relevant checks.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, web-dev
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 70/100