Commit graph

195 commits

Author SHA1 Message Date
YooLCD
540536c386 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.

(cherry picked from commit 39e382a756)
2026-04-13 16:01:16 +03:00
Doug Parker
8102331f82 test(http): disable XSRF and mock location in HttpClient tests to avoid Domino failures and state leakage
The `HttpClient` tests in `client_spec.ts` were failing intermittently in Node/Domino environment because `MockPlatformLocation` defaults to `http://_empty_/`. This valid URL satisfied the URL parser in `xsrfInterceptorFn`, causing it to proceed to cookie extraction which throws `NotYetImplemented` in Domino.

To fix this:
1. Disabled XSRF protection in `client_spec.ts` using `withNoXsrfProtection()`, as these tests are not for XSRF.
2. Provided `ɵprovideFakePlatformNavigation` to remove state leakage effects and ensure consistency.

(cherry picked from commit 1ef503e18e)
2026-04-06 18:05:58 +00:00
Jessica Janiuk
76431ed3e3 Revert "fix(http): correctly cache blob responses in transfer cache (#67002)"
This reverts commit 1f057afaac.

(cherry picked from commit 7eb33713b9)
2026-03-04 17:19:14 +00:00
SkyZeroZx
277ade97ac 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
ecf0bb4668 test(http): refactors HTTP client tests to use TestBed and providers
Updates HTTP client, JSONP, and XSRF tests to utilize `TestBed` for setup.

(cherry picked from commit ead6bb1f52)
2026-03-03 17:12:39 +00:00
Jessica Janiuk
e2e9a9a531 fix(core): adds transfer cache to httpResource to fix hydration
This should prevent the microtask problem with hydration and httpResource.

fixes: #62897
(cherry picked from commit 88685cb3b6)
2026-02-27 17:09:26 +00:00
SkyZeroZx
0c6eb60c86 test(http): remove zone-based testing utilities
Removes usages of zone-based helpers as part of the migration to zoneless tests.

Completes the transition to zoneless.
2026-02-10 07:45:00 -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
8485579649 refactor(common): remove redundant providedIn: 'root' from injection tokens
Removes unnecessary declarations from injection tokens
2025-12-12 08:05:30 -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
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
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
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
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
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
Joey Perrott
b4ae94d5ef refactor: remove TODOs which have been corrected (#63421)
Remove TODOs which were addressed but the comment was not removed

PR Close #63421
2025-08-27 11:23:57 -07:00
Joey Perrott
2fcafb65c5 build: rename defaults2.bzl to defaults.bzl (#63383)
Use defaults.bzl for the common macros

PR Close #63383
2025-08-25 15:45:01 -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
Joey Perrott
cbc258eec8 build: remove ts_project_interop infrastructure (#62908)
Remove the interop macros and final usages

PR Close #62908
2025-07-31 09:12:58 +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
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
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
Joey Perrott
4fae4dbba8 build: migrate adev to use packaged version of @angular/* packages (#62413)
Use the packaged versions of the packages instead of the local ts_project dependencies to prevent multiple versions of the deps to enter test bundles

PR Close #62413
2025-07-02 16:10:25 +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
f0965c7acd feat(http): Add support for fetch credentials options in HttpClient (#62354)
Extend Angular's HttpClient to accept the 'credentials' option from the Fetch API.

PR Close #62354
2025-06-30 10:04:55 +00:00
SkyZeroZx
27b7ec0a62 feat(http): add mode & redirect for fetch request in httpResource (#62337)
This commit adds support for the Fetch API's mode & redirect options when using httpResource with the withFetch provider

PR Close #62337
2025-06-27 15:01:52 +00:00
SkyZeroZx
87322449a3 feat(http): add support for fetch mode and redirect options in HttpClient (#62315)
Add support for mode and redirect options in Angular's HttpClient based on fech provider to enable control CORS behavior and redirect handling

PR Close #62315
2025-06-27 13:16:25 +00:00
Matthieu Riegler
aa861c42ff feat(http): add timeout option on httpResource. (#62326)
This uses the option that was introduction on the HttpClient

PR Close #62326
2025-06-27 11:21:59 +00:00
Vincent
c4cffe2063 feat(http): Add timeout option to HTTP requests (#57194)
Add timeout option to both XHR and fetch backends.

PR Close #57194
2025-06-27 09:56:25 +00:00
SkyZeroZx
55fa38a1e5 feat(http): add cache & priority support for fetch requests in httpResource (#62301)
This commit adds support for the Fetch API's cache & priority options when using httpResource with the withFetch provider

PR Close #62301
2025-06-27 09:51:31 +00:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
SkyZeroZx
9791ab1b6f feat(http): Add support for fetch request cache and priority options (#61766)
Enhances Angular HttpClient requests with Fetch API cache and priority options to optimize loading and performance.

PR Close #61766
2025-06-25 09:46:21 +00:00
SkyZeroZx
73269cf5ce feat(http): add keepalive support for fetch requests in httpResource (#61833)
This commit adds support for the Fetch API's keepalive option when using httpResource with the withFetch provider

PR Close #61833
2025-06-25 09:14:26 +00:00
Joey Perrott
3a0cfd544d build: migrate to using new jasmine_test (#62086)
Use the new jasmine_test based on rules_js instead of jasmine_node_test from rules_nodejs

PR Close #62086
2025-06-18 08:27:26 +02:00
arturovt
e947dfb84f refactor(common): use ngServerMode in HttpInterceptorHandler (#61605)
Drops `isPlatformServer(platformId)` in favor of `ngServerMode` in the `HttpInterceptorHandler`.

PR Close #61605
2025-06-04 14:13:15 -04:00
Maciej Sawicki
07811ddd7d fix(core): move reload method from Resource to WritableResource (#61441)
Now only mutable resources can be reloaded.

PR Close #61441
2025-05-21 12:06:40 -07:00
Joey Perrott
3440338d45 build: migrate common to use rules_js based toolchain (#61433)
Migrate packages/common to use ts_project and ng_project.

PR Close #61433
2025-05-20 15:07:56 +00:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Paul Gschwendtner
b763059bdd build: migrate packages/core/schematics to ts_project (#61370)
Migrates `packages/core/schematics` to `ts_project`. As part of this,
this commit cleans up some of the mixed module types and tsconfigs in
the folder. A single tsconfig (and it's test variant) are now used.

For the shipped schematics, we explicitly use the `.cjs` extension, so
that the bundles are properly recognized as CommonJS; even if they are
part of the `type: module` `@angular/core` package.

The `package.json` with `type: commonjs` is removed from
`packages/core/schematics` as it's no longer needed given the explicit
extension & caused issues as schematics are compiled with ESM but are
only later bundled for shipping & some tests as ESM.

PR Close #61370
2025-05-16 11:02:07 +00:00
Paul Gschwendtner
032b802f54 build: remove irrelevant madge circular deps tests (#61156)
We don't need this tooling anymore because we are already validating
that there are no circular dependencies via the `ng-dev` tooling that
checks `.ts` files directly.

Also these tests never actually failed to my knowledge.

PR Close #61156
2025-05-07 11:28:59 -07:00
arturovt
1e2a70c8db refactor(common): drop platform checks in HttpXsrfCookieExtractor (#59810)
Replaces `PLATFORM_ID` checks with `ngServerMode` within the `HttpXsrfCookieExtractor`. It is not part of the public API, and thus this change should not affect consumers who may have called the constructor directly.

PR Close #59810
2025-05-01 08:41:10 -07:00
cexbrayat
fc4a56d5c5 fix(common): rename httpResource function in factory (#60022)
As the function in the factory was named `httpResourceRef`, error NG0203 had with the following message:

```
Error: NG0203: httpResourceRef() can only be used within an injection context such as a constructor, a factory function, a field initializer, or a function used with `runInInjectionContext`. Find more at https://angular.dev/errors/NG0203
```

PR Close #60022
2025-04-30 08:51:39 -07:00
SkyZeroZx
ccc5cc068f feat(http): add keepalive support for fetch requests (#60621)
This commit adds support for the Fetch API's keepalive option when using HttpClient with the withFetch provider.

The change includes:
- Added keepalive to HttpRequestInit interface
- Modified FetchBackend to pass the option
- Added some unit test

PR Close #60621
2025-04-24 15:08:52 -07:00