Skip to content

feat(http): Add reponseType property to HttpResponse and HttpErrorRes… #63043

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SkyZeroZx
Copy link
Contributor

HttpResponse responseType Property Support

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

This change enhances HttpClient's alignment with the native Fetch API by exposing the response type information that indicates how the browser handled the response based on CORS policies and request mode. This provides developers with valuable insights into the nature of the response they received.

The Change Includes:

  • Added responseType property to HttpResponse and HttpErrorResponse classes
  • Maintains consistency with the Fetch API specification
  • Added comprehensive unit tests to ensure the property is correctly captured and exposed

Motivation / Use Cases

The responseType property provides crucial information about how the browser handled the response based on CORS policies and request configuration:

  • CORS Debugging: Understand why certain headers or response data might be inaccessible
  • Security Analysis: Identify opaque responses that may indicate cross-origin issues
  • Request Mode Validation: Verify that requests are being handled according to the expected CORS mode
  • API Compliance: Maintain consistency with the native Fetch API behavior
  • Performance Monitoring: Track different response types for analytics and optimization

Examples of New Usage

// Debug CORS issues by checking response type
this.http.get('https://external-api.com/data', { observe: 'response' }).subscribe({
  next: (response) => {
    if (response.responseType === 'opaque') {
      console.warn('Response is opaque - headers and body may not be accessible');
      console.warn('Consider enabling CORS on the server or using a proxy');
    } else if (response.responseType === 'cors') {
      console.log('CORS is properly configured');
      // Safe to access response headers and body
      this.processResponse(response);
    }
  }
});

@pullapprove pullapprove bot requested a review from mmalerba August 7, 2025 02:03
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: common/http Issues related to HTTP and HTTP Client labels Aug 7, 2025
@ngbot ngbot bot added this to the Backlog milestone Aug 7, 2025
@SkyZeroZx
Copy link
Contributor Author

Question : I still have doubts about the name of the property, although responseType seems correct to me, since type has already been used previously

@SkyZeroZx SkyZeroZx force-pushed the add-mode-http-response branch from 006ccfd to 5c7b86d Compare August 7, 2025 02:07
…ponse

Add support for the Fetch API's responseType property in HttpResponse and HttpErrorResponse when using HttpClient with the withFetch provider.
@SkyZeroZx SkyZeroZx force-pushed the add-mode-http-response branch from 5c7b86d to 0121b56 Compare August 7, 2025 02:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: common/http Issues related to HTTP and HTTP Client detected: feature PR contains a feature commit
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant