MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / _get_headers

Function _get_headers

slack/web/async_internal_utils.py:40–86  ·  view source on GitHub ↗

Constructs the headers need for a request. Args: has_json (bool): Whether or not the request has json. has_files (bool): Whether or not the request has files. request_specific_headers (dict): Additional headers specified by the user for a specific request. Returns:

(
    *,
    headers: dict,
    token: Optional[str],
    has_json: bool,
    has_files: bool,
    request_specific_headers: Optional[dict],
)

Source from the content-addressed store, hash-verified

38
39
40def _get_headers(
41 *,
42 headers: dict,
43 token: Optional[str],
44 has_json: bool,
45 has_files: bool,
46 request_specific_headers: Optional[dict],
47) -> Dict[str, str]:
48 """Constructs the headers need for a request.
49 Args:
50 has_json (bool): Whether or not the request has json.
51 has_files (bool): Whether or not the request has files.
52 request_specific_headers (dict): Additional headers specified by the user for a specific request.
53
54 Returns:
55 The headers dictionary.
56 e.g. {
57 'Content-Type': 'application/json;charset=utf-8',
58 'Authorization': 'Bearer xoxb-1234-1243',
59 'User-Agent': 'Python/3.7.17 slack/2.1.0 Darwin/17.7.0'
60 }
61 """
62 final_headers = {
63 "User-Agent": get_user_agent(),
64 "Content-Type": "application/x-www-form-urlencoded",
65 }
66
67 if token:
68 final_headers.update({"Authorization": "Bearer {}".format(token)})
69 if headers is None:
70 headers = {}
71
72 # Merge headers specified at client initialization.
73 final_headers.update(headers)
74
75 # Merge headers specified for a specific request. e.g. oauth.access
76 if request_specific_headers:
77 final_headers.update(request_specific_headers)
78
79 if has_json:
80 final_headers.update({"Content-Type": "application/json;charset=utf-8"})
81
82 if has_files:
83 # These are set automatically by the aiohttp library.
84 final_headers.pop("Content-Type", None)
85
86 return final_headers
87
88
89def _build_req_args(

Callers 1

_build_req_argsFunction · 0.70

Calls 1

get_user_agentFunction · 0.90

Tested by

no test coverage detected