Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: enable to return Response like object #2085

Merged
merged 2 commits into from
Jan 27, 2024

Conversation

usualoma
Copy link
Member

This PR fixes regression in the #2080.

At first glance, it appears to be a significant change from the following code, but the conditions are the same.

      if (res instanceof Response) return res

      return (async () => {
        let awaited: Response | void
        try {
          awaited = await res
          if (!awaited) {
            return this.notFoundHandler(c)
          }
        } catch (err) {
          return this.handleError(err, c)
        }
        return awaited
      })()

If res instanceof Response is false, whether it is a Promise<Response> or a Response-like object, it is resolved in the subsequent await res. Therefore, it is sufficient to check the type of res with res instanceof Promise and switch its behavior.

Author should do the followings, if applicable

  • Add tests
  • Run tests
  • yarn denoify to generate files for Deno

This improves behavior, especially in cases where Response is being overwritten on a node-server.
Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

expect(await res.text()).toBe('hello')
})
app.get(
'/proxy-object',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This - adding the tests to handle the Proxy object is good!

@yusukebe yusukebe merged commit 8c62c64 into honojs:main Jan 27, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants