Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 71c2cef

Browse files
bougwalalan-agius4
authored andcommitted
fix(@nguniversal/common): update TransferHttpResponse requiring body and headers
As per the discussion and the nice point made by @alan-agius4 regarding the TransferHttpResponse shape under angular/angular#49509. I suggest to align the status of optional and required keys of TransferHttpResponse interface of universal's interceptor to meet Angular's packages/common/http/src/transfer_cache.ts counterpart. (cherry picked from commit 654ac18)
1 parent b4dcb00 commit 71c2cef

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

modules/common/clover/src/transfer-http-cache/transfer-http-cache.interceptor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import { filter, take, tap } from 'rxjs/operators';
2222
type ResponseType = HttpRequest<unknown>['responseType'];
2323

2424
interface TransferHttpResponse {
25-
body?: any | null;
26-
headers?: Record<string, string[]>;
25+
body: any;
26+
headers: Record<string, string[]>;
2727
status?: number;
2828
statusText?: string;
2929
url?: string;
@@ -74,10 +74,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor {
7474

7575
if (this.transferState.hasKey(storeKey)) {
7676
// Request found in cache. Respond using it.
77-
const response = this.transferState.get(storeKey, {});
78-
let body: ArrayBuffer | Blob | string | undefined = response.body;
77+
const response = this.transferState.get(storeKey, null);
78+
let body: ArrayBuffer | Blob | string | undefined = response?.body;
7979

80-
switch (response.responseType) {
80+
switch (response?.responseType) {
8181
case 'arraybuffer':
8282
{
8383
// If we're in Node...
@@ -102,10 +102,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor {
102102
return of(
103103
new HttpResponse<any>({
104104
body,
105-
headers: new HttpHeaders(response.headers),
106-
status: response.status,
107-
statusText: response.statusText,
108-
url: response.url,
105+
headers: new HttpHeaders(response?.headers),
106+
status: response?.status,
107+
statusText: response?.statusText,
108+
url: response?.url,
109109
}),
110110
);
111111
}

modules/common/src/transfer_http.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ import { defaultIfEmpty, first, tap } from 'rxjs/operators';
2929

3030
type ResponseType = HttpRequest<unknown>['responseType'];
3131

32-
export interface TransferHttpResponse {
33-
body?: any | null;
34-
headers?: Record<string, string[]>;
32+
interface TransferHttpResponse {
33+
body: any;
34+
headers: Record<string, string[]>;
3535
status?: number;
3636
statusText?: string;
3737
url?: string;
@@ -96,10 +96,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor {
9696

9797
if (this.transferState.hasKey(storeKey)) {
9898
// Request found in cache. Respond using it.
99-
const response = this.transferState.get(storeKey, {});
100-
let body: ArrayBuffer | Blob | string | undefined = response.body;
99+
const response = this.transferState.get(storeKey, null);
100+
let body: ArrayBuffer | Blob | string | undefined = response?.body;
101101

102-
switch (response.responseType) {
102+
switch (response?.responseType) {
103103
case 'arraybuffer':
104104
body = new TextEncoder().encode(response.body).buffer;
105105
break;
@@ -111,10 +111,10 @@ export class TransferHttpCacheInterceptor implements HttpInterceptor {
111111
return observableOf(
112112
new HttpResponse<any>({
113113
body,
114-
headers: new HttpHeaders(response.headers),
115-
status: response.status,
116-
statusText: response.statusText,
117-
url: response.url,
114+
headers: new HttpHeaders(response?.headers),
115+
status: response?.status,
116+
statusText: response?.statusText,
117+
url: response?.url,
118118
}),
119119
);
120120
} else {

0 commit comments

Comments
 (0)