Skip to content

Commit

Permalink
feat(common): add URLSearchParams to request body
Browse files Browse the repository at this point in the history
URLSearch params are by default supported in the browser but are not supported by angular/http package added support for URLSearchParams

Fixes #36317
  • Loading branch information
ajitsinghkaler committed Jun 30, 2020
1 parent 7195625 commit bd488c9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/common/http/src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,15 @@ function isFormData(value: any): value is FormData {
return typeof FormData !== 'undefined' && value instanceof FormData;
}

/**
* Safely assert whether the given value is a URLSearchParams instance.
*
* In some execution environments URLSearchParams is not defined.
*/
function isUrlSearchParams(value: any): value is URLSearchParams {
return typeof URLSearchParams !== 'undefined' && value instanceof URLSearchParams;
}

/**
* An outgoing HTTP request with an optional typed body.
*
Expand Down Expand Up @@ -244,7 +253,7 @@ export class HttpRequest<T> {
// Check whether the body is already in a serialized form. If so,
// it can just be returned directly.
if (isArrayBuffer(this.body) || isBlob(this.body) || isFormData(this.body) ||
typeof this.body === 'string') {
isUrlSearchParams(this.body) || typeof this.body === 'string') {
return this.body;
}
// Check whether the body is an instance of HttpUrlEncodedParams.
Expand Down

0 comments on commit bd488c9

Please sign in to comment.