Commit graph

297 commits

Author SHA1 Message Date
Matthieu Riegler
6413e703fa refactor(http): refactor http options
Use shared types to ease maintenance of the http client apis.

fixes #64513
2026-04-30 15:42:32 -07:00
YooLCD
39e382a756 fix(http): add CSP nonce support to JsonpClientBackend
Add support for CSP nonces in JsonpClientBackend by injecting the CSP_NONCE token.
This ensures that dynamically created script tags for JSONP requests include the
required nonce attribute to comply with strict Content Security Policies.
2026-04-13 16:01:11 +03:00
SkyZeroZx
1f9a42bb42 refactor(http): Make Fetch API the default in HttpBackend
Updates the `HttpBackend` default provider to `FetchBackend`.

Also updates related warning messages to reflect the new default behavior.
2026-03-23 11:20:39 -07:00
Jessica Janiuk
5338b5912c Revert "refactor(http): Improves base64 encoding/decoding with feature detection (#67002)"
This reverts commit aafeb1d2bd.
2026-03-04 09:19:10 -08:00
Jessica Janiuk
7eb33713b9 Revert "fix(http): correctly cache blob responses in transfer cache (#67002)"
This reverts commit 1f057afaac.
2026-03-04 09:19:10 -08:00
SkyZeroZx
1f057afaac fix(http): correctly cache blob responses in transfer cache (#67002)
Previously, Blob values were passed to `Uint8Array` this resulted in silently producing an empty array (length = 0) without throwing an error, leading to empty cached data

PR Close #67002
2026-03-04 15:56:59 +00:00
SkyZeroZx
aafeb1d2bd refactor(http): Improves base64 encoding/decoding with feature detection (#67002)
Use feature detection for `Uint8Array.prototype.toBase64` and
`Uint8Array.fromBase64`, falling back to the existing implementation
when native support is not available

PR Close #67002
2026-03-04 15:56:59 +00:00
Miles Malerba
2206efa55f feat(core): add special return statuses for resource params
Allows throwing from the resource's params function to transition the
resource to a status other than resolved.

In particular, the following values can be thrown from params:
- `ResourceParamsStatus.IDLE` causes the resource to become `idle`
  (equivalent to returning `undefined`)
- `ResourceParamsStatus.LOADING` causes the resource to become `loading`
- Any `Error` object causes the resource to become `error` and report
  the error that was thrown via `.error()`

To simplify chaining together resources, this PR also introduces a
context object passed into to the `params` functon. This context
contains a `chain` function that can be used to get the value of a
resource that the params want to depend on, while automatically
propagating the idle, loading, and erorr states of the resource forward.
2026-03-02 08:47:14 -08:00
Jessica Janiuk
88685cb3b6 fix(core): adds transfer cache to httpResource to fix hydration
This should prevent the microtask problem with hydration and httpResource.

fixes: #62897
2026-02-27 09:09:23 -08:00
Matthieu Riegler
3bc095d508 feat(core): Add a schematics to migrate provideHttpClient to keep using the HttpXhrBackend implementation.
Exisiting applications will be migrated to keep using the XHR backend to prevent any breaking changes. `withXhr()` is to the `provideHttpClient` provider function.
2026-02-26 13:47:02 -08:00
Matthieu Riegler
5c432fb8bb feat(http): Use FetchBackend as default for the HttpBackend implementation
This commit replaces the `XhrHttpBackend` with the `FetchBackend` as the default implementation of the `HttpBackend`.
This introduces a breaking change a the `FetchBackend` does not support the report progress for uploads.

The previous behavior (`HttpXhrBackend`) can be restored by setting `withXhr()` in the `provideHttpClient()` provider function.

DEPRECATED: `withFetch` is now deprecated, it can be safely removed.
BREAKING CHANGE: Use the `HttpXhrBackend` with `provideHttpClient(withXhr)` if you want to keep supporting upload progress reports.
2026-02-26 13:47:02 -08:00
Matthieu Riegler
1416eceeea refactor(http): ensure HttpClientModule always uses the xhr backend
This is a follow-up of #67231, in preparation of making the `FetchBackend` the default
2026-02-25 08:12:14 -08:00
Matthieu Riegler
f30ed6bbf6 refactor(http): expose withXhr to prepare for fetch by default
This commit sets up the necessary changes that would allow us to safely migrate G3 before switch to the `FetchBackend` by default.

For now the `HttpXhrBackend` is still the default backend for the `HttpClient`.
2026-02-24 09:26:26 -08:00
SkyZeroZx
cb1163e5e5 fix(http): correctly parse ArrayBuffer and Blob in transfer cache
Encodes arraybuffer and blob response bodies as base64 when storing in the transfer cache, ensuring correct retrieval and usage on the client side.

Fixes #66827
2026-02-09 12:32:12 -08:00
SkyZeroZx
e38c1bf743 refactor(http): remove redundant providedIn: 'root' in XSRF_HEADER_NAME
Removes unnecessary `providedIn: 'root'` declarations from injection token
2026-01-12 10:00:24 -08:00
SkyZeroZx
8485579649 refactor(common): remove redundant providedIn: 'root' from injection tokens
Removes unnecessary declarations from injection tokens
2025-12-12 08:05:30 -08:00
Anuj Chhajed
96b79fc393 refactor(core): correct all typeof ngDevMode comparison patterns introduced by #63875
This change replaces all remaining occurrences of `typeof ngDevMode !== undefined`
with the correct `typeof ngDevMode !== 'undefined'` form. This aligns the codebase
with JavaScript typeof semantics and maintains consistency with other Angular code.
2025-12-08 10:30:01 -08:00
SkyZeroZx
7e1e396a00 docs: add documentation for HTTP_TRANSFER_CACHE_ORIGIN_MAP 2025-12-08 09:00:08 -08:00
Alan Agius
0659d11c85
fix(http): enable XSRF protection for same-origin absolute URLs
Previously, the XSRF interceptor only added the XSRF token to requests with relative URLs.
This commit updates the interceptor to also add the token to requests with absolute URLs, provided they match the current origin.
2025-12-03 12:19:43 +01:00
Alan Agius
40790ef980 fix(http): prevent XSRF token leakage to protocol-relative URLs
The XSRF interceptor previously failed to detect protocol-relative URLs (starting with `//`) as absolute URLs. This allowed requests to such URLs to include the XSRF token, potentially leaking it to external domains.

This change updates the interceptor to correctly identify protocol-relative URLs as absolute and exclude them from receiving the XSRF token.
2025-11-25 13:47:26 -05:00
hawkgs
3ae452e64f refactor(core): add debug name to resource (#64172)
Decorate `resource` (and `httpResource`) with `debugName`, along with all of its internal signals.

PR Close #64172
2025-11-24 11:30:12 -05:00
SkyZeroZx
55be477979 refactor(http): migrate XSRF classes to use inject() function
Remove constructor injection in favor of inject() calls
2025-11-10 09:49:09 -08:00
SkyZeroZx
ca3ef38143 refactor(common): Removes unused imports to clean up dependencies
Eliminates unnecessary imports to reduce clutter and improve maintainability
2025-11-06 08:35:28 -08:00
SkyZeroZx
44435ea97b refactor(http): simplifies destruction tracking using destroyed property
Replaces the manual destroyed state with destroyed property
2025-11-05 17:05:24 +00:00
arielbackenroth
07b8e953f4 refactor(http): add hooks for propagating traces across XHR callbacks.
Enables propagating a trace across XHR callbacks by providing a hook for
wrapping the callback with a function bound to the send trace context.
2025-10-28 15:08:57 +01:00
SkyZeroZx
c5e6b8bdc8 docs: Adds guide links to HTTP API docs for better discoverability 2025-10-27 09:25:56 +01:00
Andrew Kushnir
fc65107506 Revert "refactor(core): add debug name to resource (#64172)" (#64418)
This reverts commit 63180067aa.

PR Close #64418
2025-10-14 14:28:16 -07:00
hawkgs
63180067aa refactor(core): add debug name to resource (#64172)
Decorate `resource` (and `httpResource`) with `debugName`, along with all of its internal signals.

PR Close #64172
2025-10-14 09:31:41 -07:00
SkyZeroZx
2739b7975b feat(http): add referrerPolicy option to HttpResource (#64283)
Adds support for the `referrerPolicy` option in `HttpResource`, allowing developers to control how much referrer information is sent with each HTTP request.

PR Close #64283
2025-10-13 10:00:27 -07:00
SkyZeroZx
5cbdefcf11 feat(http): add support for fetch referrerPolicy option in HttpClient (#64116)
Introduces a referrer policy option for HTTP requests to allow specifying the referrer information sent, improving privacy and security controls.

PR Close #64116
2025-10-07 20:45:34 -04:00
Jeremy Kescher
0e4e17cd97 refactor(http): HttpResponseBase.statusText (#64176)
Since HTTP/2, responses no longer contain a status text besides the status code, which caused our default value of 'OK' to be used in HttpErrorResponse.message.

DEPRECATED: `HttpResponseBase.statusText` is deprecated

PR Close #64176
2025-10-02 07:50:29 -07:00
JoostK
50d9d55f49 fix(core): fix narrowing of Resource.hasValue() (#63994)
This commit changes `Resource.hasValue()` and its derived types to improve narrowing
of resources whose generic type either does not include `undefined` (i.e. when a default
value has been provided) or when the generic type is `unknown`. This fixes the undesirable
behavior where `hasValue()` would cause the `else` branch of an `hasValue()` conditional
to have a narrowed type of `never`, given that the `hasValue()`'s type guard covers the
entire type range already (meaning that the type in the else-branch cannot be inhabited
in the type system, yielding the `never` type).

By making the `hasValue()` method only a type guard when the generic type includes `undefined`
these problems are avoided.

Fixes #60766
Fixes #63545
Fixes #63982

PR Close #63994
2025-09-23 14:20:55 +00:00
Matthieu Riegler
c50d659509 refactor(core): protect InjectionToken usage of ngDevMode (#63875)
Since those are top level APIs, `ngDevMode` might not be available at runtime if they're invoked before the variable is set.

fixes #62796

PR Close #63875
2025-09-19 21:27:45 +00:00
SkyZeroZx
3327de1b88 docs: add documentation for NG02802 warning about HttpTransferCache headers (#63802)
add documentation for NG02802 warning about HttpTransferCache headers

PR Close #63802
2025-09-15 15:38:24 +00:00
SkyZeroZx
07e678872f feat(http): Add reponseType property to HttpResponse and HttpErrorResponse (#63043)
Add support for the Fetch API's responseType property in HttpResponse and HttpErrorResponse when using HttpClient with the withFetch provider.

PR Close #63043
2025-08-28 08:34:56 -07:00
Matthieu Riegler
6489af7678 refactor(http): rework the HttpEvent union to improve narrowing. (#63267)
Prior to this change, `HttpProgressEvent` could not be narrowed to `HttpDownloadProgressEvent` or `HttpUploadProgressEvent`

PR Close #63267
2025-08-27 11:25:02 -07:00
arturovt
1ebba5442f refactor(common): drop X-Request-URL (#61943)
This commit drops the `X-Request-URL` header. It was a non-standard HTTP response header, deprecated long ago and never part of any official specification. Modern browsers now expose the final URL via the `XMLHttpRequest.responseURL` property, as defined in the WHATWG spec.

PR Close #61943
2025-08-25 08:45:19 -07:00
Matthieu Riegler
4bed062bc9 feat(http): Provide http services in root (#56212)
The changes introduced in this commit allows to use the HttpClient without the provider function.

PR Close #56212
2025-08-14 13:04:35 +02:00
Vincent
e5d6fb5825 fix(http): Reset headers, progress, and statusCode when using set() in HttpResource (#62873)
Currently, those values aren't reset, which means they are out of sync with the new value

PR Close #62873
2025-08-01 08:08:52 +00:00
SkyZeroZx
245494ad29 fix(http): add missing http options allowed in fetch API (#62881)
The addBody function was not preserving all fetch API options like integrity and referrer when creating request options for POST/PUT/PATCH requests. This caused these options to be stripped out during request construction.

PR Close #62881
2025-07-30 14:07:41 +00:00
SkyZeroZx
0984b30388 feat(http): Add redirected property to HttpResponse and HttpErrorResponse (#62675)
Add 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.

PR Close #62675
2025-07-24 13:19:22 +00:00
Sebastian Barfurth
1b73c23597 fix(http): propagate plain errors when parsing fails (#62765)
The fetch backend now propagates the plain body when parsing the body fails.
This replicates the behavior of the XHR backend introduced in #19773.

The current state completely obfuscates errors of the "wrong" response type.
However, it's not uncommon for successful requests to return one type and
errors to return another type. Propagating the plain error allows downstream
error consumers to reason about the error body and decide how to parse it
depending on application needs.

PR Close #62765
2025-07-24 09:23:24 +00:00
Vincent
1408baff45 fix(http): Add missing timeout and transferCache options to HttpClient (#62586)
The `timeout` option is implemented in the different HTTP backends, but the option is not actually passed to the backends. `transferCache` is also missing in one signature. This commit adds both options to `HttpClient`.

Fixes #62581

PR Close #62586
2025-07-14 15:45:25 -07:00
Kristiyan Kostadinov
745ea44394 feat(core): support TypeScript 5.9 (#62541)
Updates the repo to support TypeScript 5.9 and expands the allowed version range.

PR Close #62541
2025-07-14 14:04:58 -07:00
SkyZeroZx
be811fee79 feat(http): add referrer & integrity support for fetch requests in httpResource (#62461)
This commit adds support for the Fetch API's referrer & integrity options when using httpResource with the withFetch provider

PR Close #62461
2025-07-14 11:40:54 -07:00
SkyZeroZx
3c1f5857ac refactor(http): use RuntimeError for invalid timeout error (#62490)
Replace generic Error with RuntimeError

PR Close #62490
2025-07-11 10:38:56 -07:00
Alan Agius
75a5d08c5e fix(http): do not display warnings Angular detected that a HttpClient request with the keepalive option was sent using XHR when option is not true (#62536)
Currently, this warning is always displayed as the option defaults to false. We update the logic to only display the warning when it's true.

PR Close #62536
2025-07-09 12:45:27 -07:00
SkyZeroZx
1cf9d9064c feat(http): Add support for fetch referrer & integrity options in HttpClient (#62417)
Enhances Angular HttpClient requests with Fetch API referrer and integrity options to optimize security

PR Close #62417
2025-07-03 08:07:36 +00:00
SkyZeroZx
b6ef42843c feat(http): add credentials support for fetch requests in httpResource (#62390)
This commit adds support for the Fetch API's credentials option when using httpResource with the withFetch provider

PR Close #62390
2025-07-01 13:37:56 +00:00
SkyZeroZx
cfbbb08437 feat(http): add warning when withCredentials overrides explicit credentials (#62383)
This will prevent confusion and accidentally overriding of credentials.

PR Close #62383
2025-07-01 09:21:35 +00:00