Skip to content

feat(http): add support for fetch mode and redirect options in HttpCl… - #62315

Closed
SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-fetch-control
Closed

SkyZeroZx wants to merge 1 commit into
angular:mainfrom
SkyZeroZx:add-fetch-control

Conversation

@SkyZeroZx

Copy link
Copy Markdown
Contributor

This commit adds support for the Fetch API's mode and redirect options when using HttpClient with the withFetch provider.

The change includes:

  • Added mode and redirect to the HttpRequestInit interface
  • Modified FetchBackend to pass the options
  • Modifed in simple function in xhr to show warning messages
  • Added unit tests to validate behavior

Motivation / Use Cases

The mode and redirect options are particularly useful for:

  • mode controls the request's CORS policy ('cors', 'no-cors', 'same-origin'), helping manage security boundaries and cross-origin resource sharing.

  • redirect determines how redirects are handled ('follow', 'manual', 'error'), allowing developers to explicitly accept, reject, or handle redirections manually.

  • These options help ensure secure data access across origins, enforce strict network policies, and give developers more control over how external resources are handled.


Proposed Solution

  • Add mode and redirect to the HttpRequestInit interface
  • Implement property handling in the HttpRequest class
  • Pass the options through FetchBackend to the native Fetch API
  • Maintain full backward compatibility

Examples of New Usage

// POST request with mode and redirect
http.post('/api/register', {
      mode: 'same-origin',
      redirect : 'follow',
}).subscribe();

@pullapprove
pullapprove Bot requested a review from alxhub June 27, 2025 03:17
@angular-robot angular-robot Bot added detected: feature PR contains a feature commit area: common/http Issues related to HTTP and HTTP Client labels Jun 27, 2025
@ngbot ngbot Bot added this to the Backlog milestone Jun 27, 2025

@thePunderWoman thePunderWoman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!

reviewed-for: fw-general, public-api

@pullapprove
pullapprove Bot requested review from AndrewKushnir and crisbeto June 27, 2025 08:47

@crisbeto crisbeto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@thePunderWoman thePunderWoman added target: minor This PR is targeted for the next minor release action: merge The PR is ready for merge by the caretaker labels Jun 27, 2025
Comment thread packages/common/http/src/xhr.ts Resolved
@alan-agius4 alan-agius4 added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: merge The PR is ready for merge by the caretaker labels Jun 27, 2025
Comment thread packages/common/http/src/request.ts Resolved
Comment thread packages/common/http/src/request.ts Resolved
@JeanMeche
JeanMeche force-pushed the add-fetch-control branch 2 times, most recently from af458f9 to 93cc91a Compare June 27, 2025 12:24
@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Jun 27, 2025
…ient

Add support for mode and redirect options in Angular's HttpClient based on fech provider to enable control CORS behavior and redirect handling
@thePunderWoman

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 8732244.

The changes were merged into the following branches: main

AndrewKushnir added a commit to AndrewKushnir/angular that referenced this pull request Jun 27, 2025
AndrewKushnir added a commit to AndrewKushnir/angular that referenced this pull request Jun 27, 2025
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 28, 2025
@SkyZeroZx
SkyZeroZx deleted the add-fetch-control branch December 17, 2025 21:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: common/http Issues related to HTTP and HTTP Client detected: feature PR contains a feature commit target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants