Skip to content

Commit

Permalink
feat: remove the PUBSUB_HEADER_PREFIX variable unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
diegodfreire authored and joaodaher committed Aug 10, 2023
1 parent f961e4a commit 78a6cd4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
1 change: 0 additions & 1 deletion django_cloud_tasks/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def __init__(self, *args, **kwargs):
self.eager = self._fetch_config(name="EAGER", default=False)
self.tasks_url_name = self._fetch_config(name="URL_NAME", default="tasks-endpoint")
self.subscribers_url_name = self._fetch_config(name="SUBSCRIBERS_URL_NAME", default="subscriptions-endpoint")
self.pubsub_header_prefix = self._fetch_config(name="PUBSUB_HEADER_PREFIX", default="HTTP_")

self.subscribers_max_retries = self._fetch_config(name="SUBSCRIBER_MAX_RETRIES", default=None)
self.subscribers_min_backoff = self._fetch_config(name="SUBSCRIBER_MIN_BACKOFF", default=None)
Expand Down
3 changes: 1 addition & 2 deletions django_cloud_tasks/middleware/pubsub_headers_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, get_response):
self.get_response = get_response
app: DjangoCloudTasksAppConfig = apps.get_app_config("django_cloud_tasks")
self.url_name = app.subscribers_url_name
self.pubsub_header_prefix = app.pubsub_header_prefix
self.propagated_headers_key = app.propagated_headers_key

def __call__(self, request):
Expand Down Expand Up @@ -54,5 +53,5 @@ def extract_headers(self, request) -> dict[str, Any]:
headers = {}
message_headers = message.data.get(self.propagated_headers_key) or {}
for key, value in message_headers.items():
headers[key.removeprefix(self.pubsub_header_prefix)] = value
headers[key] = value
return headers
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def trigger_subscriber(self, content):

def test_propagate_headers(self):
headers = {
"HTTP_traceparent": "trace-this-potato",
"traceparent": "trace-this-potato",
}
content = self.make_content(headers=headers)

Expand All @@ -38,13 +38,13 @@ def test_propagate_headers(self):
expected_kwargs = {
"queue_name": "tasks",
"url": "http://localhost:8080/tasks/CalculatePriceTask",
"payload": '{"price": 10, "quantity": 42, "_http_headers": {"HTTP_traceparent": "trace-this-potato"}}',
"payload": '{"price": 10, "quantity": 42, "_http_headers": {"traceparent": "trace-this-potato"}}',
"headers": {"Traceparent": "trace-this-potato", "X-CloudTasks-Projectname": ANY},
}
push.assert_called_once_with(**expected_kwargs)

def test_propagate_headers_as_uppercase(self):
headers = {"HTTP_X-Forwarded-Authorization": "user-token"}
headers = {"X-Forwarded-Authorization": "user-token"}
content = self.make_content(headers=headers)

with patch("gcp_pilot.tasks.CloudTasks.push"), patch("django_cloud_tasks.tasks.TaskMetadata.from_task_obj"):
Expand Down

0 comments on commit 78a6cd4

Please sign in to comment.