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

Function _get_headers

slack_sdk/web/internal_utils.py:76–123  ·  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

74
75
76def _get_headers(
77 *,
78 headers: dict,
79 token: Optional[str],
80 has_json: bool,
81 has_files: bool,
82 request_specific_headers: Optional[dict],
83) -> Dict[str, str]:
84 """Constructs the headers need for a request.
85 Args:
86 has_json (bool): Whether or not the request has json.
87 has_files (bool): Whether or not the request has files.
88 request_specific_headers (dict): Additional headers specified by the user for a specific request.
89
90 Returns:
91 The headers dictionary.
92 e.g. {
93 'Content-Type': 'application/json;charset=utf-8',
94 'Authorization': 'Bearer xoxb-1234-1243',
95 'User-Agent': 'Python/3.7.17 slack/2.1.0 Darwin/17.7.0'
96 }
97 """
98 final_headers = {
99 "Content-Type": "application/x-www-form-urlencoded",
100 }
101 if headers is None or "User-Agent" not in headers:
102 final_headers["User-Agent"] = get_user_agent()
103
104 if token:
105 final_headers.update({"Authorization": "Bearer {}".format(token)})
106 if headers is None:
107 headers = {}
108
109 # Merge headers specified at client initialization.
110 final_headers.update(headers)
111
112 # Merge headers specified for a specific request. e.g. oauth.access
113 if request_specific_headers:
114 final_headers.update(request_specific_headers)
115
116 if has_json:
117 final_headers.update({"Content-Type": "application/json;charset=utf-8"})
118
119 if has_files:
120 # These are set automatically by the aiohttp library.
121 final_headers.pop("Content-Type", None)
122
123 return final_headers
124
125
126def _set_default_params(target: dict, default_params: dict) -> None:

Callers 1

_build_req_argsFunction · 0.70

Calls 1

get_user_agentFunction · 0.85

Tested by

no test coverage detected