intercom: Return success on HEAD requests.

Intercom sends a HEAD request to validate the webhook URL on their side,
which was not expected in the previous implementation.
This fixes the problem that we send out a confusing error message for it.

Fixes #23912.

Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
Zixuan James Li
2023-01-06 19:27:53 +08:00
committed by Tim Abbott
parent 6fb4f10abb
commit 1e36d79b83
2 changed files with 7 additions and 1 deletions

View File

@@ -265,3 +265,7 @@ New user created:
"Contact: Eeshan Garg",
"User unsubscribed from emails.",
)
def test_success_on_http_head(self) -> None:
result = self.client_head(self.url)
self.assertEqual(result.status_code, 200)

View File

@@ -4,7 +4,7 @@ from typing import Callable, Dict, List, Tuple
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.decorator import return_success_on_head_request, webhook_view
from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
@@ -325,6 +325,8 @@ ALL_EVENT_TYPES = list(EVENT_TO_FUNCTION_MAPPER.keys())
@webhook_view("Intercom", all_event_types=ALL_EVENT_TYPES)
# Intercom sends a HEAD request to validate the webhook URL. In this case, we just assume success.
@return_success_on_head_request
@has_request_variables
def api_intercom_webhook(
request: HttpRequest,