Skip to content

HttpRequest.clone forgets transferCache #54924

@cclausen

Description

@cclausen

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

No

Description

When cloning the HttpRequest, like keycloak does in it's interceptor, the clone-method forgets the transferCache-property.

req.transferCache = true;
this.keycloak.addTokenToHeader(req.headers).pipe(mergeMap(headersWithBearer => {
      const kcReq = req.clone({
        headers: headersWithBearer
      });
      return next.handle(kcReq);
    }));
req.transferCache === true;
kcReq.transferCache === undefined;

The HttpRequest-constructor expects the transferCache to be set in the options-parameter, but the clone-method does not provide it.

This code should fix the problem.

`
const transferCache = update.transferCache || this.transferCache ;

// Finally, construct the new HttpRequest using the pieces from above.
return new HttpRequest(method, url, body, {
  params,
  headers,
  context,
  reportProgress,
  responseType,
  withCredentials,
 transferCache ,
});`

Please provide a link to a minimal reproduction of the bug

No response

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 17.3.0
Node: 20.9.0
Package Manager: npm 10.1.0
OS: win32 x64

Angular: 17.3.0
... animations, cli, common, compiler, compiler-cli, core, forms
... localize, platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.0
@angular-devkit/build-angular   17.3.0
@angular-devkit/core            17.3.0
@angular-devkit/schematics      17.3.0
@schematics/angular             17.3.0
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2The issue is important to a large percentage of users, with a workaroundarea: common/httpIssues related to HTTP and HTTP Clientbuggood first issueLabel noting a good first issue to be worked on by a community memberopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).state: has PR

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions