Skip to content

Commit

Permalink
feat(common): add protected PlatformResponse.formatHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita committed Feb 29, 2024
1 parent 307e8a7 commit 67ade57
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/platform/common/src/services/PlatformResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,7 @@ export class PlatformResponse<Res extends Record<string, any> = any> {
}

setHeader(key: string, item: any) {
if (key.toLowerCase() === "location") {
// "back" is an alias for the referrer
if (item === "back") {
item = this.request.get("Referrer") || "/";
}

item = encodeUrl(String(item));
}

this.raw.set(key, item);
this.raw.set(key, this.formatHeader(key, item));

return this;
}
Expand Down Expand Up @@ -238,6 +229,7 @@ export class PlatformResponse<Res extends Record<string, any> = any> {

return this;
}

/**
* Sets the response Location HTTP header to the specified path parameter.
*
Expand Down Expand Up @@ -363,6 +355,18 @@ export class PlatformResponse<Res extends Record<string, any> = any> {
return this;
}

protected formatHeader(key: string, item: any) {
if (key.toLowerCase() === "location") {
// "back" is an alias for the referrer
if (item === "back") {
item = this.request.get("Referrer") || "/";
}

item = encodeUrl(String(item));
}
return item;
}

protected json(data: any) {
this.raw.json(data);

Expand Down

0 comments on commit 67ade57

Please sign in to comment.