Skip to content

Commit

Permalink
Fix empty return values for header fields
Browse files Browse the repository at this point in the history
  • Loading branch information
christiand93 committed Feb 6, 2024
1 parent 5ccedcf commit 083c6c4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lib/middleware/framework-services/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FrameworkService } from "../interfaces";

export default class ExpressService implements FrameworkService {

getReqHeaderField(req: any, fieldName: string): string {
getReqHeaderField(req: any, fieldName: string): string | undefined {
return req.header(fieldName);
}

Expand Down Expand Up @@ -30,7 +30,7 @@ export default class ExpressService implements FrameworkService {
return value
}

getResHeaderField(res: any, fieldName: string): string {
getResHeaderField(res: any, fieldName: string): string | undefined {
return res.get(fieldName);
}

Expand Down
7 changes: 3 additions & 4 deletions src/lib/middleware/framework-services/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { FrameworkService } from "../interfaces";

export default class FastifyService implements FrameworkService {

getReqHeaderField(req: any, fieldName: string): string {
return req.headers[fieldName] ? req.headers[fieldName] : ""
getReqHeaderField(req: any, fieldName: string): string | undefined {
return req.headers[fieldName]
}

getReqField(req: any, fieldName: string): any {
Expand Down Expand Up @@ -31,8 +31,7 @@ export default class FastifyService implements FrameworkService {
}

getResHeaderField(res: any, fieldName: string): string {
let value = res.getHeader(fieldName)
return value ? value : "";
return res.getHeader(fieldName)
}

getResField(res: any, fieldName: string): any {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/middleware/framework-services/plainhttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class HttpService implements FrameworkService {
}

getResHeaderField(res: any, fieldName: string): string {
return res.getHeader ? res.getHeader(fieldName) : "";
return res.getHeader ? res.getHeader(fieldName) : undefined;
}

getResField(res: any, fieldName: string): any {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/middleware/framework-services/restify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class RestifyService implements FrameworkService {
}

getResHeaderField(res: any, fieldName: string): string {
return res.get ? res.get(fieldName) : "";
return res.get ? res.get(fieldName) : undefined;
}

getResField(res: any, fieldName: string): any {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/middleware/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export interface FrameworkService {
getReqHeaderField(req: any, fieldName: string): string;
getReqHeaderField(req: any, fieldName: string): string | undefined;
getReqField(req: any, fieldName: string): string | number | boolean | undefined;
getResHeaderField(req: any, fieldName: string): string;
getResHeaderField(req: any, fieldName: string): string | undefined;
getResField(req: any, fieldName: string): string | number | boolean | undefined;
onResFinish(res: any, handler: () => void): undefined;
}
2 changes: 1 addition & 1 deletion src/lib/middleware/requestAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class RequestAccessor {
return RequestAccessor.instance;
}

getHeaderField(req: any, fieldName: string): string {
getHeaderField(req: any, fieldName: string): string | undefined {
return this.frameworkService.getReqHeaderField(req, fieldName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/middleware/responseAccessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class ResponseAccessor {
return ResponseAccessor.instance;
}

getHeaderField(res: any, fieldName: string): string {
getHeaderField(res: any, fieldName: string): string | undefined {
return this.frameworkService.getResHeaderField(res, fieldName);
}

Expand Down

0 comments on commit 083c6c4

Please sign in to comment.