Skip to content

Commit

Permalink
refactor: reduce toString call
Browse files Browse the repository at this point in the history
  • Loading branch information
climba03003 committed Jan 27, 2024
1 parent e4a537a commit 833f0c5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,8 @@ function onSendEnd (reply, payload) {

// since Response contain status code, we need to update before
// any action that used statusCode
if (toString.call(payload) === '[object Response]') {
const isResponse = toString.call(payload) === '[object Response]'
if (isResponse) {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/status
if (typeof payload.status === 'number') {
reply.code(payload.status)
Expand Down Expand Up @@ -650,7 +651,7 @@ function onSendEnd (reply, payload) {
}

// Response
if (toString.call(payload) === '[object Response]') {
if (isResponse) {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/headers
if (typeof payload.headers === 'object' && typeof payload.headers.forEach === 'function') {
for (const [headerName, headerValue] of payload.headers) {
Expand Down

0 comments on commit 833f0c5

Please sign in to comment.