Skip to content

Commit e6a721b

Browse files
authored
feat: add referer header to download request (#1366)
1 parent 68e505f commit e6a721b

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

functions-python/batch_process_dataset/src/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,8 +332,9 @@ def generate_temp_filename(self):
332332
"""
333333
Generates a temporary filename
334334
"""
335+
working_dir = os.getenv("WORKING_DIR", "/in-memory")
335336
temporary_file_path = (
336-
f"/in-memory/{self.feed_stable_id}-{random.randint(0, 1000000)}.zip"
337+
f"{working_dir}/{self.feed_stable_id}-{random.randint(0, 1000000)}.zip"
337338
)
338339
return temporary_file_path
339340

functions-python/batch_process_dataset/src/scripts/download_verifier.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def verify_upload_dataset(producer_url: str):
6868
# Replace with actual producer URL
6969
try:
7070
os.environ["STORAGE_EMULATOR_HOST"] = f"http://{HOST}:{PORT}"
71+
os.environ["WORKING_DIR"] = "/tmp/verifier"
72+
# create working dir if not exists
73+
if not os.path.exists(os.environ["WORKING_DIR"]):
74+
os.makedirs(os.environ["WORKING_DIR"])
7175
server = create_server(
7276
host=HOST, port=PORT, in_memory=False, default_bucket=BUCKET_NAME
7377
)

functions-python/helpers/tests/test_helpers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def test_download_and_get_hash_auth_type_header(self):
104104
preload_content=False,
105105
headers={
106106
"User-Agent": expected_user_agent,
107+
"Referer": url,
107108
api_key_parameter_name: credentials,
108109
},
109110
redirect=True,
@@ -155,7 +156,7 @@ def test_download_and_get_hash_auth_type_api_key(self):
155156
"GET",
156157
modified_url,
157158
preload_content=False,
158-
headers={"User-Agent": expected_user_agent},
159+
headers={"User-Agent": expected_user_agent, "Referer": base_url},
159160
redirect=True,
160161
)
161162

functions-python/helpers/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ def download_and_get_hash(
149149
headers = {
150150
"User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
151151
"AppleWebKit/537.36 (KHTML, like Gecko) "
152-
"Chrome/126.0.0.0 Mobile Safari/537.36"
152+
"Chrome/126.0.0.0 Mobile Safari/537.36",
153+
"Referer": url,
153154
}
154155
# Careful, some URLs may already contain a query string
155156
# (e.g. http://api.511.org/transit/datafeeds?operator_id=CE)

0 commit comments

Comments
 (0)