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: Use status code specified in context #87

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

snorremd
Copy link

@snorremd snorremd commented Mar 30, 2024

Fix #56

Previously the html plugin would always return 200 for HTML responses. This commit adds support for reading the status code in set.status to determine which status code to use. It fallbacks to 200 if no status code is set. It uses the StatusMap exported by Elysia to map res.status values supplied as string literals.

Example for statuscode has been added to examples folder showcasing returning Forbidden status. Added test for overriding status code.

Needed to upgrade Elysia peer and dev dependency to a newer version as the StatusMap value was not available in elysia 1.0.2. Running bun install and pnpm install also updated the patch versions of @kitajs/* dependencies.

Fix elysiajs#56

Previously the html plugin would always return 200 for HTML responses.
This commit adds support for reading the status code in set.status to
determine which status code to use. It fallbacks to 200 if no status
code is set. It uses the StatusMap exported by Elysia to map res.status
values supplied as string literals.

Example for statuscode has been added to examples folder showcasing
returning Forbidden status. Added test for overriding status code.

Needed to upgrade Elysia peer and dev dependency to a newer version as
the StatusMap value was not available in elysia 1.0.2. Running bun
install and pnpm install also updated the patch versions of @kitajs/*
dependencies.
@snorremd
Copy link
Author

snorremd commented Apr 2, 2024

If preferable, to keep backwards compatibility, one could introduce a new option to enable HTTP status codes for HTML which defaults to false. This way existing elysia-html users won't be affected while those that want to have all the HTTP status codes can enable this behaviour.

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.

Returning html always return a HTTP 200 status code
1 participant