Skip to content

Commit 2694668

Browse files
committed
Add ssl support in WebhookClient
1 parent 8d90a97 commit 2694668

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

slack/webhook/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import logging
33
import re
44
from http.client import HTTPResponse
5+
from ssl import SSLContext
56
from typing import Dict, Union, List, Optional
67
from urllib.error import HTTPError
78
from urllib.request import Request, urlopen
@@ -20,17 +21,20 @@ def __init__(
2021
self,
2122
url: str,
2223
timeout: int = 30,
24+
ssl: Optional[SSLContext] = None,
2325
proxy: Optional[str] = None,
2426
default_headers: Dict[str, str] = {},
2527
):
2628
"""API client for Incoming Webhooks and response_url
2729
:param url: a complete URL to send data (e.g., https://hooks.slack.com/XXX)
2830
:param timeout: request timeout (in seconds)
31+
:param ssl: ssl.SSLContext to use for requests
2932
:param proxy: proxy URL (e.g., localhost:9000, http://localhost:9000)
3033
:param default_headers: request headers to add to all requests
3134
"""
3235
self.url = url
3336
self.timeout = timeout
37+
self.ssl = ssl
3438
self.proxy = proxy
3539
self.default_headers = default_headers
3640

@@ -107,7 +111,7 @@ def _perform_http_request(
107111
else:
108112
raise SlackRequestError(f"Invalid URL detected: {url}")
109113

110-
resp: HTTPResponse = urlopen(req, timeout=self.timeout)
114+
resp: HTTPResponse = urlopen(req, context=self.ssl, timeout=self.timeout)
111115
charset: str = resp.headers.get_content_charset() or "utf-8"
112116
response_body: str = resp.read().decode(charset)
113117
resp = WebhookResponse(

0 commit comments

Comments
 (0)