outgoing webhooks: Set a Zulip-specific user-agent.

This now sets the user-agent to something like:

    ZulipOutgoingWebhook/2.0

(It uses the current ZULIP_VERSION.)

Before this change, the user-agent would be
something like `python-requests/2.18.4`.

Fixes #10741
This commit is contained in:
Steve Howell
2019-01-09 14:29:17 +00:00
committed by Tim Abbott
parent a3ac94fa26
commit 475108b784
2 changed files with 22 additions and 1 deletions

View File

@@ -21,6 +21,8 @@ from zerver.lib.url_encoding import near_message_url
from zerver.lib.validator import check_dict, check_string
from zerver.decorator import JsonableError
from version import ZULIP_VERSION
class OutgoingWebhookServiceInterface:
def __init__(self, token: str, user_profile: UserProfile, service_name: str) -> None:
@@ -41,7 +43,11 @@ class GenericOutgoingWebhookService(OutgoingWebhookServiceInterface):
def send_data_to_server(self,
base_url: str,
request_data: Any) -> Response:
headers = {'content-type': 'application/json'}
user_agent = 'ZulipOutgoingWebhook/' + ZULIP_VERSION
headers = {
'content-type': 'application/json',
'User-Agent': user_agent,
}
response = requests.request('POST', base_url, data=request_data, headers=headers)
return response