Skip to content

Commit 9488a3f

Browse files
JeanMechepkozlowski-opensource
authored andcommitted
fix(http): Send query params on fetch request (#50740)
QueryParams were missing when using the `FetchBackend`. Fixes #50728 PR Close #50740
1 parent d274afc commit 9488a3f

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/common/http/src/fetch.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class FetchBackend implements HttpBackend {
6565
let response;
6666

6767
try {
68-
const fetchPromise = this.fetchImpl(request.url, {signal, ...init});
68+
const fetchPromise = this.fetchImpl(request.urlWithParams, {signal, ...init});
6969

7070
// Make sure Zone.js doesn't trigger false-positive unhandled promise
7171
// error in case the Promise is rejected synchronously. See function
@@ -81,15 +81,15 @@ export class FetchBackend implements HttpBackend {
8181
error,
8282
status: error.status ?? 0,
8383
statusText: error.statusText,
84-
url: request.url,
84+
url: request.urlWithParams,
8585
headers: error.headers,
8686
}));
8787
return;
8888
}
8989

9090
const headers = new HttpHeaders(response.headers);
9191
const statusText = response.statusText;
92-
const url = getResponseUrl(response) ?? request.url;
92+
const url = getResponseUrl(response) ?? request.urlWithParams;
9393

9494
let status = response.status;
9595
let body: string|ArrayBuffer|Blob|object|null = null;
@@ -143,7 +143,7 @@ export class FetchBackend implements HttpBackend {
143143
headers: new HttpHeaders(response.headers),
144144
status: response.status,
145145
statusText: response.statusText,
146-
url: getResponseUrl(response) ?? request.url,
146+
url: getResponseUrl(response) ?? request.urlWithParams,
147147
}));
148148
return;
149149
}

packages/common/http/test/fetch_spec.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {TestBed} from '@angular/core/testing';
1111
import {Observable, of, Subject} from 'rxjs';
1212
import {catchError, retry, scan, skip, take, toArray} from 'rxjs/operators';
1313

14-
import {HttpDownloadProgressEvent, HttpErrorResponse, HttpHeaderResponse, HttpStatusCode} from '../public_api';
14+
import {HttpDownloadProgressEvent, HttpErrorResponse, HttpHeaderResponse, HttpParams, HttpStatusCode} from '../public_api';
1515
import {FetchBackend, FetchFactory} from '../src/fetch';
1616

1717
function trackEvents(obs: Observable<any>): Promise<any[]> {
@@ -94,6 +94,16 @@ describe('FetchBackend', async () => {
9494
expect(fetchMock.request.url).toBe('/test');
9595
});
9696

97+
it('use query params from request', () => {
98+
const requestWithQuery = new HttpRequest('GET', '/test', 'some body', {
99+
params: new HttpParams({fromObject: {query: 'foobar'}}),
100+
responseType: 'text',
101+
});
102+
callFetchAndFlush(requestWithQuery);
103+
expect(fetchMock.request.method).toBe('GET');
104+
expect(fetchMock.request.url).toBe('/test?query=foobar');
105+
});
106+
97107
it('sets outgoing body correctly', () => {
98108
callFetchAndFlush(TEST_POST);
99109
expect(fetchMock.request.body).toBe('some body');

0 commit comments

Comments
 (0)