diff --git a/app/main.py b/app/main.py index 8feb465..16e8a55 100644 --- a/app/main.py +++ b/app/main.py @@ -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()