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

[openbsd] Tests for "if-modified-since" header are failing #67

Open
epsilon-0 opened this issue Aug 25, 2024 · 2 comments
Open

[openbsd] Tests for "if-modified-since" header are failing #67

epsilon-0 opened this issue Aug 25, 2024 · 2 comments

Comments

@epsilon-0
Copy link

All the test_files tests are failing for both asgi and wsgi in the case for "if-modified-since" header. Other header scenarios are passing with a valid 304 being returned but this particular one returns a 200 for some reason

_______________________________ test_files[app0] _______________________________

app = <baize.wsgi.staticfiles.Files object at 0x1f80642fbd0>

    @pytest.mark.parametrize(
        "app",
        [
            Files(Path(__file__).absolute().parent.parent / "baize"),
            Files(".", "baize"),
            Files(".", "baize", handle_404=PlainTextResponse("", 404)),
        ],
    )
    def test_files(app):
        with httpx.Client(app=app, base_url="http://testServer/") as client:
            resp = client.get("/py.typed")
            assert resp.text == ""

            assert (
                client.get("/py.typed", headers={"if-none-match": resp.headers["etag"]})
            ).status_code == 304

            assert (
                client.get(
                    "/py.typed", headers={"if-none-match": "W/" + resp.headers["etag"]}
                )
            ).status_code == 304

            assert (
                client.get("/py.typed", headers={"if-none-match": "*"})
            ).status_code == 304

>           assert (
                client.get(
                    "/py.typed",
                    headers={"if-modified-since": resp.headers["last-modified"]},
                )
            ).status_code == 304
E           AssertionError: assert 200 == 304
E            +  where 200 = <Response [200 OK]>.status_code
E            +    where <Response [200 OK]> = <bound method Client.get of <httpx.Client object at 0x1f7b018f4d0>>('/py.typed', headers={'if-modified-since': 'Fri, 26 Jul 2024 15:42:11 GMT'})
E            +      where <bound method Client.get of <httpx.Client object at 0x1f7b018f4d0>> = <httpx.Client object at 0x1f7b018f4d0>.get

tests/test_wsgi.py:641: AssertionError
@epsilon-0
Copy link
Author

Seems like the solution is to use st_mtime instead of st_ctime as the response header uses st_mtime in the original response but for some reason the comparison for the if-modified-since uses the st_ctime. st_ctime is changed even when you change permissions of the file, which isn't something that you would normally want to care about for the http response.

@abersheeran
Copy link
Owner

Welcome PR

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

No branches or pull requests

2 participants