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