Add Cache-Control headers
This commit is contained in:
parent
38416f103f
commit
d090e90ee2
@ -42,7 +42,8 @@ class GeoLocation(BaseModel):
|
||||
|
||||
@app.post("/")
|
||||
async def root_post(ipaddresses: Annotated[list[IPAddressParam],
|
||||
Body(title="The IPAddresses to geolocate")]
|
||||
Body(title="The IPAddresses to geolocate")],
|
||||
response: Response
|
||||
) -> list[GeoLocation]:
|
||||
'''
|
||||
Return GeoLocation item(s) for a list of IPAddressParam objects
|
||||
@ -72,6 +73,8 @@ async def root_post(ipaddresses: Annotated[list[IPAddressParam],
|
||||
ip=ipaddress.ip
|
||||
)
|
||||
)
|
||||
if geolocations:
|
||||
response.headers['Cache-Control'] = 'private, max-age=604800'
|
||||
return geolocations
|
||||
|
||||
|
||||
@ -85,6 +88,7 @@ async def root_get(ipaddress: Annotated[Union[IPv4Address,IPv6Address],
|
||||
'''
|
||||
locations = await root_post([IPAddressParam(ip=ipaddress)])
|
||||
if locations:
|
||||
response.headers['Cache-Control'] = 'private, max-age=604800'
|
||||
return locations.pop()
|
||||
response.status_code = status.HTTP_404_NOT_FOUND
|
||||
return GeoLocation()
|
||||
|
Loading…
x
Reference in New Issue
Block a user