You can use the Bitbucket API to get the timestamp of the last deployment. You can use the following code to get the timestamp of the last deployment:
import requests
url = 'https://api.bitbucket.org/2.0/repositories/{username}/{repo_name}/pipelines/{pipeline_id}/'
response = requests.get(url)
if response.status_code == 200:
data = response.json()
last_deployment_timestamp = data['updated_on']
You can then use the last_deployment_timestamp to set the last-modified header.