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

If response has a header, written status code is ignored #144

Open
Aksem opened this issue Oct 22, 2023 · 1 comment
Open

If response has a header, written status code is ignored #144

Aksem opened this issue Oct 22, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Aksem
Copy link

Aksem commented Oct 22, 2023

Describe the bug
If at least one header is written in response and then status code, e.g. 404, then provided status code is ignored and is always 200. Without header, status code is correct.

To Reproduce
Steps to reproduce the behavior:

  1. Start socketify app with following implementation:
from socketify import App


def handler(response, req):
    response.write_header(
        "Access-Control-Allow-Origin", "*"
    )
    response.write_status(404)
    response.end("Not found")


app = App()
app.any("/*", handler)
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()
  1. Send any request to localhost:3000
  2. Check status code, it is 200 instead of expected 404.

Expected behavior
Status code 404.

Desktop (please complete the following information):

  • OS: Linux

Additional context
Without response.write_header call, status code is 404 as expected.

@cirospaciari cirospaciari added the bug Something isn't working label Feb 1, 2024
@cirospaciari
Copy link
Owner

Right now the solution is call write_status first, this is a uWS thing https://github.com/cirospaciari/uWebSockets/blob/d5ec941fd8d29f3df6afbc73164d3c8bf0f49079/src/Http3Response.h#L33-L41 will change this in the future

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants