Commit graph

116 commits

Author SHA1 Message Date
Bob Watson
a6d953e145 docs: move tour of heroes tutorial to a subdirectory (#48162)
This commit prepares the documentation directories for future tutorials organized by directory.

Also, it moves the Angular Libraries topic from the Tutorials section to Developer Guides in TOC

PR Close #48162
2022-12-12 12:07:46 -08:00
Alex Rickabaugh
febf29dd51 fix(http): rename withLegacyInterceptors to withInterceptorsFromDi (#47901)
This rename reflects what the function actually does. Although the intention
is still not to have two different interceptor mechanisms, that is now
communicated in the docs for the function instead of in its name.

Fixes #47764

PR Close #47901
2022-11-03 17:54:03 -07:00
Alex Rickabaugh
cf6c819489 docs(http): add public API tags and jsdoc for provideHttpClient (#47901)
This commit adds documentation and API tagging for `provideHttpClient` and
the `with*` feature functions.

PR Close #47901
2022-11-03 17:54:03 -07:00
Andrew Kushnir
ddbc4931e6 refactor(common): make provideHttpClient return EnvironmentProviders (#47758)
This commit updates the `provideHttpClient` function to return the `EnvironmentProviders` instead of a regular `Provider[]`, to make sure that the `provideHttpClient` can only be used where an environment is being setup.

PR Close #47758
2022-10-13 16:44:59 +00:00
Alex Rickabaugh
ea16a98dfe fix(http): better handle unexpected undefined XSRF tokens (#47683)
`HttpXsrfTokenExtractor` allows returning `string|null` for an XSRF token,
and the interceptor checked if the returned token is `null`. However, some
implementations return `undefined` instead (behind an `any`) type, which
caused the interceptor to crash when trying to set an `undefined` value for
the header.

This commit makes the XSRF interceptor a little more resilient against such
broken implementations of the `HttpXsrfTokenExtractor` interface.

PR Close #47683
2022-10-06 16:41:06 -07:00
Alex Rickabaugh
c09c1bb033 docs(http): fix copy-paste error in HttpClientJsonpModule docs (#47502)
This commit deletes a sentence from the `HttpClientJsonpModule` docs which
was accidentally copy-pasted from the docs for another symbol.

PR Close #47502
2022-10-06 19:02:46 +00:00
Alex Rickabaugh
3ba99e286a feat(http): allow for child HttpClients to request via parents (#47502)
Ordinarily, providing `HttpClient` (either via `provideHttpClient` or the
`HttpClientModule`) creates an entirely separate HTTP context. Requests made
via that client are not passed through the interceptor chains that are
configured in a parent injector, for this example.

This commit introduces a new option for `provideHttpClient` called
`withRequestsMadeViaParent()`. When this option is passed, requests made in
the child context flow through any injectors, etc. and are then handed off
to the parent context.

This addresses a longstanding issue with interceptors where it's not
possible to extend the set of interceptors in a child context without
repeating all of the interceptors from the parent.

PR Close #47502
2022-10-06 19:02:46 +00:00
Alex Rickabaugh
62c7a7a16e feat(http): introduce functional interceptors (#47502)
This commit introduces a new feature for `provideHttpClient` called
`withInterceptors`. This feature exposes and configures the new concept of
functional interceptors.

Functional interceptors use functions instead of classes to implement an
HTTP interceptor. Such interceptor functions have access to the DI context
from the `EnvironmentInjector` in which they're configured via the
`inject()` function. Otherwise, functional interceptors are identical in
capability to the existing interceptor system.

PR Close #47502
2022-10-06 19:02:46 +00:00
Alex Rickabaugh
fc69c8021c refactor(http): convert NgModules to use provideHttpClient internally (#47502)
This commit converts `HttpClientModule` to use `provideHttpClient()`
internally, with a particular configuration of features. Other NgModules
related to configuring `HttpClient` are also converted to use the providers
directly from various features, to ensure consistency of behavior.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
e47b129070 feat(http): introduce the provideHttpClient() API (#47502)
This commit introduces the main components of the `provideHttpClient()`
provider API, designed in the style of `provideRouter()`. Initial features
are defined for including legacy class-based interceptors, JSONP support,
and configuring or disabling the builtin XSRF protection.

This API is an alternative to providing `HttpClient` via the
`HttpClientModule`, and is more tree-shakable and more capable than the
NgModule implementation.

Tests are included to validate the new configuration format as well as the
interoperability of the two styles of providing and configuring
`HttpClient`.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
67ef8b19b3 refactor(http): convert the XSRF interceptor to functional style (#47502)
This commit converts the XSRF interceptor into a functional interceptor
instead of a legacy class-based interceptor.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
ab6a3d7d03 refactor(http): provide XSRF configuration tokens in root (#47502)
This commit switches the XSRF configuration tokens (for header name and
cookie name) to be `providedIn: 'root'`. This is a no-op change now as they
are always provided along with any usage of them via `HttpClientModule`, but
will become load-bearing as the `provideHttpClient` API will not provide
these tokens, and will rely on injecting them from either the parent context
or from these root providers.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
d98d8d7645 refactor(http): use an InjectionToken to disable the XSRF interceptor (#47502)
@angular/common/http has XSRF protection which is enabled by default and is
implemented as an interceptor. Previously, this protection could be disabled
with an API which would internally provide a `NoopInterceptor` in place of
the standard XSRF interceptor.

To achieve the same capability of disabling the XSRF interceptor after it is
converted to the functional style, an InjectionToken is added in this commit
which disables the XSRF interceptor. This way, the interceptor can be
disabled in place without needing to override it via DI (which is difficult
for functional interceptors).

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
c3ecd8f5c8 refactor(http): convert the JSONP interceptor to the functional style (#47502)
This commit rewrites the JSONP interceptor to use the functional interceptor
style internally, while still maintaining the same public API and behavior.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
546f9ca299 refactor(http): use a DI token for new interceptors (#47502)
This commit introduces a new DI token for the set of functional
interceptors. This is a no-op in terms of behavior currently, but will allow
for the deduplication of the bridge interceptor which connects legacy class-
based interceptors to the functional interceptor chain.

PR Close #47502
2022-10-06 19:02:45 +00:00
Alex Rickabaugh
d7683a611a refactor(http): introduce the functional interceptors API (#47502)
This commit introduces new types and symbols related to functional HTTP
interceptors - interceptors which are plain functions with access to DI via
the `inject()` operation.

This new form of interceptor is not exposed publically in this commit, but
the legacy class-based interceptors are refactored to be built on top of the
new API internally.

PR Close #47502
2022-10-06 19:02:45 +00:00
Daniel Ostrovsky
f8e78e3f9b docs(http): Update HttClient "JSON object" to "JavaScript object" (#47325)
updated all references of "JSON object" to "JavaScript object" in HttpClient `common/http/src/client.ts`

Fixes #43242

PR Close #47325
2022-09-03 11:00:43 -07:00
Giovanni Alberto Rivas
5dd72b7610 docs(http): replace http method return description (#47322)
PR Close #47322
2022-09-01 19:14:56 -07:00
John Vandenberg
c14c701775 docs: fix spelling (#46713)
PR Close #46713
2022-07-08 20:54:52 +00:00
markostanimirovic
82acbf919b feat(http): improve error message for nullish header (#46059)
This commit improves the error message for nullish headers.

Fixes #46048

PR Close #46059
2022-06-16 14:39:41 -07:00
cexbrayat
10691c626b fix(common): properly cast http param values to strings (#42643)
Before this commit, when initializing `HttpParams` with:

    const body = new HttpParams({fromObject: {b: 2}});

then `body.get('b')` returned `2` instead of `'2'` as expected.

This commit makes sure the values are converted to strings in such cases.

Fixes #42641

PR Close #42643
2022-05-04 12:43:37 -07:00
Adrian Kunz
76a9a24cdc fix(http): encode + signs in query params as %2B (angular#11058) (#45111)
Servers always decode + as a space, which is undesirable when one
actually wants to query for a plus.

BREAKING CHANGE:

Queries including + will now actually query for + instead of space.
Most workarounds involving custom codecs will be unaffected.
Possible server-side workarounds will need to be undone.

Fixes angular#11058

PR Close #45111
2022-04-20 09:00:19 -07:00
Maddie Klein
d43c0e973f fix(http): Throw error when headers are supplied in JSONP request (#45210)
JSONP does not support headers being set on requests. This
enables JSONP to throw an error when headers are supplied
in the request to prevent attempts to set them.

BREAKING CHANGE: JSONP will throw an error when headers are set on a reques

JSONP does not support headers being set on requests. Before when
a request was sent to a JSONP backend that had headers set the headers
were ignored. The JSONP backend will now throw an error if it
receives a request that has any headers set. Any uses of JSONP
on requests with headers set will need to remove the headers
to avoid the error.

Closes #9141

PR Close #45210
2022-03-28 09:38:19 -07:00
Martin Sikora
909b21aa29 refactor(http): change <script>'s ownerDocument in jsonp teardown (#36807)
handler

Cancel pending json handler by adopting its <script> element into
another document
(https://html.spec.whatwg.org/multipage/scripting.html#execute-the-script-block)
This way the browser will prevent the script from being parsed and executed.

Fixes #34818

PR Close #36807
2022-02-24 17:24:33 +00:00
Martin Sikora
7671a1e40d fix(common): canceled JSONP requests won't throw console error with missing callback function (#36807)
This commit fixes a use-case where unsubscribing from a JSONP request will result in "Uncaught ReferenceError: ng_jsonp_callback_xy is not defined"
thrown into console. Unsubscribing won't remove its associated callback function because the requested script will finish
loading anyway and will try to call the handler.

PR Close #34818

PR Close #36807
2022-02-24 17:24:33 +00:00
Ramzan
28393031b1 perf(http): remove IE special status handling (#44354)
revert the condition as dev only

PR Close #44354
2022-02-04 11:45:15 -08:00
HyperLife1119
d452b388bd feat(http): add has() method to HttpContext class (#43887)
At present, the get() method provided by HttpContext will never return null. Sometimes we need to check whether an http token is included, so add the has() method to HttpContext.

PR Close #43887
2021-11-04 18:52:18 +00:00
Daniel Díaz
6ff0eef35a docs(http): get rid of not needed space at the end of the sentence (#43528)
PR Close #43528
2021-09-22 16:18:08 +00:00
William Sedlacek
3b6595d450 docs(common): correct typos in jsdoc of http client (#43352)
This corrects four typos in the HttpClient JSDoc
capabilites => capabilities
reuested => requested
wuth => with
responmse => response
PR Close #43352
2021-09-07 18:45:16 +00:00
Edoardo Dusi
85c345b011 refactor(common): change encoding function in httpparams for better performances and coding standards (#42998)
HttpParams uses custom encoding function "standardEncoding" to encode query string preserving specific charachters. This refactoring aims to improve performances and code quality of that function by using a RegExp and a Map object instead of a chain of replace functions.

PR Close #42998
2021-08-16 10:44:52 -07:00
Paul Gschwendtner
22290af178 refactor(common): ensure compatibility with noImplicitOverride (#42512)
Adds the `override` keyword to the `common` sources to ensure
compatibility with `noImplicitOverride`.

PR Close #42512
2021-07-12 13:11:16 -07:00
Paul Gschwendtner
2d0ff0a5d3 ci: add lint error for files with missing trailing new-line (#42478)
For quite a while it is an unspoken convention to add a trailing
new-line files within the Angular repository. This was never enforced
automatically, but has been frequently raised in pull requests through
manual review. This commit sets up a lint rule so that this is
"officially" enforced and doesn't require manual review.

PR Close #42478
2021-06-04 13:31:03 -07:00
Ajit Singh
4bc3cf216d feat(common): add URLSearchParams to request body (#37852)
URLSearch params are by default supported in the browser but are not supported by angular/http package added support for URLSearchParams

Fixes #36317

PR Close #37852
2021-05-07 10:45:02 -04:00
Gopal Jayaraman
6b8baad940 fix(common): add body as an optional property on the options of HttpClient.delete (#19438) (#41723)
adding optional body for HTTP delete request options. This new param added as an optional so won't break the existing code also provide the capability the send the body when and where it required.

PR Close #41723
2021-05-04 21:09:58 -07:00
Gopal Jayaraman
6e11febf60 fix(common): add right ContentType for boolean values with HttpClient request body(#38924) (#41885)
currently a boolean as body is seen as text/plain, where is should be seen as application/json, since it is valid JSON, like numbers.

PR Close #41885
2021-05-03 10:00:16 -07:00
Alan Agius
e0028e5741 fix(platform-browser): configure XhrFactory to use BrowserXhr (#41313)
With this change we move `XhrFactory` to the root entrypoint of `@angular/commmon`, this is needed so that we can configure `XhrFactory` DI token at a platform level, and not add a dependency  between `@angular/platform-browser` and `@angular/common/http`.

Currently, when using `HttpClientModule` in a child module on the server, `ReferenceError: XMLHttpRequest is not defined` is being thrown because the child module has its own Injector and causes `XhrFactory` provider to be configured to use `BrowserXhr`.
Therefore, we should configure the `XhrFactory` at a platform level similar to other Browser specific providers.

BREAKING CHANGE:

`XhrFactory` has been moved from `@angular/common/http` to `@angular/common`.

**Before**
```ts
import {XhrFactory} from '@angular/common/http';
```

**After**
```ts
import {XhrFactory} from '@angular/common';
```

Closes #41311

PR Close #41313
2021-03-29 15:14:16 -07:00
FDIM
1644d64398 feat(compiler-cli): introduce HttpContext request context (#25751)
A long-requested feature for HttpClient is the ability to store and retrieve
custom metadata for requests, especially in interceptors. This commit
implements this functionality via a new context object for requests.

Each outgoing HttpRequest now has an associated "context", an instance of
the HttpContext class. An HttpContext can be provided when making a request,
or if not then an empty context is created for the new request. This context
shares its lifecycle with the entire request, even across operations that
change the identity of the HttpRequest instance such as RxJS retries.

The HttpContext functions as an expando. Users can create typed tokens as instances of HttpContextToken, and
read/write a value for the key from any HttpContext object.

This commit implements the HttpContext functionality. A followup commit will
add angular.io documentation.

PR Close #25751
2021-03-15 10:33:48 -07:00
Chris
ad40fcae7a docs: improve documentation on how to pass a stringified parameter list to HttpClient (#41010)
Fixes #40618

PR Close #41010
2021-03-04 11:00:23 -08:00
cexbrayat
91cdc11aa0 fix(common): allow number or boolean as http params (#40663)
This change fixes an incompatibility between the old `@angular/http` package
and its successor (`@angular/common/http`) by re-introducing the types that were supported before.

It now allows to use number and boolean directly as HTTP params, instead of having to convert it to string first.

Before:

    this.http.get('/api/config', { params: { page: `${page}` } });

After:

    this.http.get('/api/config', { params: { page }});

`HttpParams` has also been updated to have most of its methods accept number or boolean values.

Fixes #23856

BREAKING CHANGE:

The methods of the `HttpParams` class now accept `string | number | boolean`
instead of `string` for the value of a parameter.
If you extended this class in your application,
you'll have to update the signatures of your methods to reflect these changes.

PR Close #40663
2021-02-26 12:03:50 -08:00
Jefiozie
f340a5b9f2 fix(http): ignore question mark when params are parsed (#40610)
This commit adds a fix where params will ignore questions marks when
parsed.

Fixes #28722

PR Close #40610
2021-02-19 12:11:39 -08:00
Dmitry Drobyshev
38972653fa fix(http): emit error on XMLHttpRequest abort event (#40767)
Before this change, when Google Chrome cancels a XMLHttpRequest, an Observable of the response
never finishes. This happens, for example, when you put your computer to sleep or just press
Ctrl+S to save the browser page. After this commit, if request is canceled or aborted an
appropriate Observable will be completed with an error.

Fixes #22324

PR Close #40767
2021-02-10 11:13:05 -08:00
arturovt
61a0b6de6d fix(http): complete the request on timeout (#39807)
When using the [timeout attribute](https://xhr.spec.whatwg.org/#the-timeout-attribute) and an XHR
request times out, browsers trigger the `timeout` event (and execute the XHR's `ontimeout`
callback). Additionally, Safari 9 handles timed-out requests in the same way, even if no `timeout`
has been explicitly set on the XHR.

In the above cases, `HttpClient` would fail to capture the XHR's completing (with an error), so
the corresponding `Observable` would never complete.

PR Close #26453

PR Close #39807
2021-02-09 14:44:17 -08:00
Quentin Focheux
6fe3a1de7f feat(http): expose a list of human-readable http status codes (#23548)
They aim to improve code readability.
Since they are defined by `const enum` they have zero runtime performance impact
over just using constant literals.

Fixes #23543

PR Close #23548
2021-01-28 09:10:48 -08:00
Harun Urhan
575a2d162c feat(common): implement appendAll() method on HttpParams (#20930)
Adds an `appendAll()` method to `HttpParams` that can construct the HTTP
request/response body from an object of parameters and values.

This avoids calling `append()` multiple times when multiple parameters
need to be added.

Fixes #20798

PR Close #20930
2021-01-21 14:01:34 -08:00
Alexey Elin
cf02cf1e18 docs: remove duplicated the (#40434)
PR Close #40434
2021-01-14 11:33:57 -08:00
Nicholas Papadopoulos
7851a254d8 docs(common): fix typo in HttpClient docs (#39904)
PR Close #39904
2020-12-02 11:16:43 -08:00
Fabian Wiles
7a5bc95614 refactor(http): inline HttpObserve (#18417)
Inline `HttpObserve` for better type safety.

Fix #18146

PR Close #18417
2020-12-01 12:13:04 -08:00
Tzimpoulas Nikos
1539c64fb0 docs(common): change HTTPResponse to HttpResponse (#39860)
PR Close #39860
2020-11-30 12:04:34 -08:00
Gautier Pelloux-Prayer
938abc03bc docs(http): Add mention to default value 'OK' for statusText. #23334 (#23494)
PR Close #23494
2020-11-23 08:31:24 -08:00
Marcono1234
3e1e5a15ba docs: update links to use HTTPS as protocol (#39718)
PR Close #39718
2020-11-20 12:52:16 -08:00