"Date" header not changing between requests
See original GitHub issueDiscussed in https://github.com/encode/uvicorn/discussions/1610
<div type='discussions-op-text'>Originally posted by arjwilliams August 22, 2022 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())
```</div>
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
"Date" header not changing between requests #1610 - GitHub
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...
Read more >Why is the Date header not set when I make a WebRequest in ...
My requests to Google are failing though due to a missing "Date" header. Fiddler confirms that a Date header is not being sent...
Read more >Using The Date Header Field In HTTP Requests - IETF
Most HTTP clients have no need to use the Date header field in requests. This only changes if it is important that the...
Read more >Date - HTTP - MDN Web Docs - Mozilla
The Date general HTTP header contains the date and time at which the message originated.
Read more >HTTP/1.1: Header Field Definitions
Note: If the request does not include an Accept-Encoding field, and if the ... or 101 (Switching Protocols), the response MAY include a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This will be available in uvicorn
0.19.0
.Correct. This is not a bug.