"Date" header not changing between requests #1610
-
I am testing out some cache-control headers in my web app, but the auto-generated "Date" header seems to only be changing when a new connection is established, rather than with each new request, which is preventing the browser from caching new responses, as it sees the response as being older than it actually is. I would expect that the "Date" header to change between requests, even when using an existing connection. I am testing on Python 3.10.5, with Uvicorn 0.18.2. Possible test case, which is currently failing for me: import asyncio
from email.utils import parsedate_to_datetime
from contextlib import asynccontextmanager
import httpx
from uvicorn import Config, Server
async def test_default_date_header_different():
config = Config(app=app, loop="asyncio", limit_max_requests=2)
async with run_server(config):
async with httpx.AsyncClient() as client:
response1 = await client.get("http://127.0.0.1:8000")
await asyncio.sleep(2)
response2 = await client.get("http://127.0.0.1:8000")
response1_date = parsedate_to_datetime(response1.headers["date"])
response2_date = parsedate_to_datetime(response2.headers["date"])
assert(response2_date > response1_date)
async def app(scope, receive, send):
assert scope["type"] == "http"
await send({"type": "http.response.start", "status": 200, "headers": []})
await send({"type": "http.response.body", "body": b"", "more_body": False})
@asynccontextmanager
async def run_server(config: Config):
server = Server(config=config)
cancel_handle = asyncio.ensure_future(server.serve())
await asyncio.sleep(0.1)
try:
yield server
finally:
await server.shutdown()
cancel_handle.cancel()
asyncio.run(test_date_header_different()) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I checked the behavior with hypercorn (Daphne, doesn't support date header) Server Code from hypercorn import Config
from hypercorn.asyncio import serve
config = Config()
config.max_app_queue_size=2
asyncio.run(serve(app, config)) The >response1_date = parsedate_to_datetime(response1.headers["date"])
>response2_date = parsedate_to_datetime(response2.headers["date"])
>print(response2_date, response1_date)
2022-08-30 18:29:09+00:00 2022-08-30 18:29:07+00:00 |
Beta Was this translation helpful? Give feedback.
-
This was solved already. I don't remember when, but on 0.20.0 it's already working. |
Beta Was this translation helpful? Give feedback.
This was solved already. I don't remember when, but on 0.20.0 it's already working.