Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat(http): Add redirected property to HttpResponse and HttpErrorResp…#62675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
SkyZeroZx wants to merge1 commit intoangular:main
base:main
Choose a base branch
Loading
fromSkyZeroZx:add-redirect-option-http-response

Conversation

SkyZeroZx
Copy link
Contributor

@SkyZeroZxSkyZeroZx commentedJul 17, 2025
edited
Loading

HttpResponseredirected Property Support

This commit adds support for the Fetch API's redirected property in HttpResponse and HttpErrorResponse when using HttpClient with the withFetch provider.

This change builds on the functionality introduced in#62315, which added support for passing the redirect option to the Fetch API. With redirects now configurable, exposing the redirected property provides developers with a way to determine if a response was the result of a redirect, further aligning HttpClient's behavior with the native Fetch API and enhancing observability of request flow

The Change Includes:

  • Addedredirected property toHttpResponse andHttpErrorResponse classes
  • UpdatedFetchBackend to capture and forward theredirected flag from the native fetch response
  • Maintains consistency with the Fetch API specification
  • Added unit tests to ensure the property is correctly captured and exposed

Motivation / Use Cases

Theredirected property provides valuable information about whether the response was the result of a redirect:

  • Security: Detect when requests have been redirected, which is important for security-sensitive applications
  • Analytics: Track redirect behavior for performance monitoring and debugging
  • Conditional Logic: Implement different handling based on whether a response was redirected
  • API Compliance: Maintain consistency with the native Fetch API behavior

Examples of New Usage

Basic Redirect Detection

import{HttpClient}from'@angular/common/http';constructor(privatehttp:HttpClient){}// Detect if the response was redirectedthis.http.get('/api/data',{observe:'response'}).subscribe({next:(response)=>{if(response.redirected){console.log('Response was redirected');console.log('Final URL:',response.url);}}});

Conditional Logic Based on Redirects

// Handle different scenarios based on redirect statusthis.http.get('/api/user-profile',{observe:'response'}).subscribe({next:(response)=>{if(response.redirected){// User might have been redirected to login pagethis.handlePossibleAuthRedirect(response);}else{// Direct response, process normallythis.processUserProfile(response.body);}}});

…onseAdd support for the Fetch API's redirected property in HttpResponse and HttpErrorResponse when using HttpClient with the withFetch provider.The redirected property indicates whether the response was the result of an HTTP redirect, providing valuable information for security, debugging, and conditional logic.
@pullapprovepullapprovebot requested a review fromkirjsJuly 17, 2025 00:30
@angular-robotangular-robotbot added detected: featurePR contains a feature commit area: common/httpIssues related to HTTP and HTTP Client labelsJul 17, 2025
@ngbotngbotbot added this to theBacklog milestoneJul 17, 2025
@SkyZeroZx
Copy link
ContributorAuthor

@JeanMeche it's possible to try to run it again because failed the last time

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kirjskirjsAwaiting requested review from kirjs

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
area: common/httpIssues related to HTTP and HTTP Clientdetected: featurePR contains a feature commit
Projects
None yet
Milestone
Backlog
Development

Successfully merging this pull request may close these issues.

1 participant
@SkyZeroZx

[8]ページ先頭

©2009-2025 Movatter.jp