Skip to content

Commit 9493417

Browse files
Merge branch 'main' into dependabot/pip/pyramid-gte-2.1-and-lt-3
2 parents b650df4 + 3978707 commit 9493417

29 files changed

Lines changed: 350 additions & 95 deletions

File tree

docs/reference/adapter/asgi/base_handler.html

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,13 @@ <h2 class="section-title" id="header-classes">Classes</h2>
8888
return AsgiHttpResponse(status=bolt_response.status, headers=bolt_response.headers, body=bolt_response.body)
8989
return AsgiHttpResponse(status=404, headers={&#34;content-type&#34;: [&#34;text/plain;charset=utf-8&#34;]}, body=&#34;Not Found&#34;)
9090

91-
async def _handle_lifespan(self, receive: Callable) -&gt; Dict[str, str]:
92-
while True:
93-
lifespan = await receive()
94-
if lifespan[&#34;type&#34;] == &#34;lifespan.startup&#34;:
95-
&#34;&#34;&#34;Do something before startup&#34;&#34;&#34;
96-
return {&#34;type&#34;: &#34;lifespan.startup.complete&#34;}
97-
if lifespan[&#34;type&#34;] == &#34;lifespan.shutdown&#34;:
98-
&#34;&#34;&#34;Do something before shutdown&#34;&#34;&#34;
99-
return {&#34;type&#34;: &#34;lifespan.shutdown.complete&#34;}
91+
async def _handle_lifespan(self, receive: Callable, send: Callable) -&gt; None:
92+
message = await receive()
93+
if message[&#34;type&#34;] == &#34;lifespan.startup&#34;:
94+
await send({&#34;type&#34;: &#34;lifespan.startup.complete&#34;})
95+
message = await receive()
96+
if message[&#34;type&#34;] == &#34;lifespan.shutdown&#34;:
97+
await send({&#34;type&#34;: &#34;lifespan.shutdown.complete&#34;})
10098

10199
async def __call__(self, scope: scope_type, receive: Callable, send: Callable) -&gt; None:
102100
if scope[&#34;type&#34;] == &#34;http&#34;:
@@ -107,7 +105,7 @@ <h2 class="section-title" id="header-classes">Classes</h2>
107105
await send(response.get_response_body())
108106
return
109107
if scope[&#34;type&#34;] == &#34;lifespan&#34;:
110-
await send(await self._handle_lifespan(receive))
108+
await self._handle_lifespan(receive, send)
111109
return
112110
raise TypeError(f&#34;Unsupported scope type: {scope[&#39;type&#39;]!r}&#34;)</code></pre>
113111
</details>

docs/reference/adapter/asgi/http_response.html

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ <h2 class="section-title" id="header-classes">Classes</h2>
6060

6161
def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
6262
self.status: int = status
63-
self.raw_headers: List[Tuple[bytes, bytes]] = [
64-
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
65-
]
66-
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
6763
self.body: bytes = bytes(body, ENCODING)
64+
self.raw_headers: List[Tuple[bytes, bytes]] = []
65+
for key, values in headers.items():
66+
if key.lower() == &#34;content-length&#34;:
67+
continue
68+
for v in values:
69+
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
70+
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))
6871

6972
def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
7073
return {
@@ -94,11 +97,14 @@ <h3>Instance variables</h3>
9497

9598
def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
9699
self.status: int = status
97-
self.raw_headers: List[Tuple[bytes, bytes]] = [
98-
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
99-
]
100-
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
101100
self.body: bytes = bytes(body, ENCODING)
101+
self.raw_headers: List[Tuple[bytes, bytes]] = []
102+
for key, values in headers.items():
103+
if key.lower() == &#34;content-length&#34;:
104+
continue
105+
for v in values:
106+
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
107+
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))
102108

103109
def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
104110
return {
@@ -127,11 +133,14 @@ <h3>Instance variables</h3>
127133

128134
def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
129135
self.status: int = status
130-
self.raw_headers: List[Tuple[bytes, bytes]] = [
131-
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
132-
]
133-
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
134136
self.body: bytes = bytes(body, ENCODING)
137+
self.raw_headers: List[Tuple[bytes, bytes]] = []
138+
for key, values in headers.items():
139+
if key.lower() == &#34;content-length&#34;:
140+
continue
141+
for v in values:
142+
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
143+
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))
135144

136145
def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
137146
return {
@@ -160,11 +169,14 @@ <h3>Instance variables</h3>
160169

161170
def __init__(self, status: int, headers: Dict[str, Sequence[str]] = {}, body: str = &#34;&#34;):
162171
self.status: int = status
163-
self.raw_headers: List[Tuple[bytes, bytes]] = [
164-
(bytes(key, ENCODING), bytes(value[0], ENCODING)) for key, value in headers.items()
165-
]
166-
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(body)), ENCODING)))
167172
self.body: bytes = bytes(body, ENCODING)
173+
self.raw_headers: List[Tuple[bytes, bytes]] = []
174+
for key, values in headers.items():
175+
if key.lower() == &#34;content-length&#34;:
176+
continue
177+
for v in values:
178+
self.raw_headers.append((bytes(key, ENCODING), bytes(v, ENCODING)))
179+
self.raw_headers.append((b&#34;content-length&#34;, bytes(str(len(self.body)), ENCODING)))
168180

169181
def get_response_start(self) -&gt; Dict[str, Union[str, int, Iterable[Tuple[bytes, bytes]]]]:
170182
return {

docs/reference/adapter/falcon/async_resource.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
8585
await self._write_response(bolt_resp, resp)
8686
return
8787

88-
resp.status = &#34;404&#34;
89-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
90-
resp.body = &#34;The page is not found...&#34;
88+
resp.status = HTTPStatus.NOT_FOUND
89+
resp.content_type = MEDIA_TEXT
90+
resp.text = &#34;The page is not found...&#34;
9191

9292
async def on_post(self, req: Request, resp: Response):
9393
bolt_req = await self._to_bolt_request(req)
@@ -149,9 +149,9 @@ <h3>Methods</h3>
149149
await self._write_response(bolt_resp, resp)
150150
return
151151

152-
resp.status = &#34;404&#34;
153-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
154-
resp.body = &#34;The page is not found...&#34;</code></pre>
152+
resp.status = HTTPStatus.NOT_FOUND
153+
resp.content_type = MEDIA_TEXT
154+
resp.text = &#34;The page is not found...&#34;</code></pre>
155155
</details>
156156
<div class="desc"></div>
157157
</dd>

docs/reference/adapter/falcon/index.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
9191
self._write_response(bolt_resp, resp)
9292
return
9393

94-
resp.status = &#34;404&#34;
95-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
96-
resp.body = &#34;The page is not found...&#34;
94+
resp.status = HTTPStatus.NOT_FOUND
95+
resp.content_type = MEDIA_TEXT
96+
resp.text = &#34;The page is not found...&#34;
9797

9898
def on_post(self, req: Request, resp: Response):
9999
bolt_req = self._to_bolt_request(req)
@@ -159,9 +159,9 @@ <h3>Methods</h3>
159159
self._write_response(bolt_resp, resp)
160160
return
161161

162-
resp.status = &#34;404&#34;
163-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
164-
resp.body = &#34;The page is not found...&#34;</code></pre>
162+
resp.status = HTTPStatus.NOT_FOUND
163+
resp.content_type = MEDIA_TEXT
164+
resp.text = &#34;The page is not found...&#34;</code></pre>
165165
</details>
166166
<div class="desc"></div>
167167
</dd>

docs/reference/adapter/falcon/resource.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
8080
self._write_response(bolt_resp, resp)
8181
return
8282

83-
resp.status = &#34;404&#34;
84-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
85-
resp.body = &#34;The page is not found...&#34;
83+
resp.status = HTTPStatus.NOT_FOUND
84+
resp.content_type = MEDIA_TEXT
85+
resp.text = &#34;The page is not found...&#34;
8686

8787
def on_post(self, req: Request, resp: Response):
8888
bolt_req = self._to_bolt_request(req)
@@ -148,9 +148,9 @@ <h3>Methods</h3>
148148
self._write_response(bolt_resp, resp)
149149
return
150150

151-
resp.status = &#34;404&#34;
152-
# Falcon 4.x w/ mypy fails to correctly infer the str type here
153-
resp.body = &#34;The page is not found...&#34;</code></pre>
151+
resp.status = HTTPStatus.NOT_FOUND
152+
resp.content_type = MEDIA_TEXT
153+
resp.text = &#34;The page is not found...&#34;</code></pre>
154154
</details>
155155
<div class="desc"></div>
156156
</dd>

docs/reference/adapter/socket_mode/async_internals.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
5454
<span>Expand source code</span>
5555
</summary>
5656
<pre><code class="python">async def run_async_bolt_app(app: AsyncApp, req: SocketModeRequest):
57-
bolt_req: AsyncBoltRequest = AsyncBoltRequest(mode=&#34;socket_mode&#34;, body=req.payload)
57+
bolt_req: AsyncBoltRequest = AsyncBoltRequest(mode=&#34;socket_mode&#34;, body=req.payload, headers=build_headers(req))
5858
bolt_resp: BoltResponse = await app.async_dispatch(bolt_req)
5959
return bolt_resp</code></pre>
6060
</details>

docs/reference/adapter/socket_mode/internals.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,25 @@ <h1 class="title">Module <code>slack_bolt.adapter.socket_mode.internals</code></
4545
<section>
4646
<h2 class="section-title" id="header-functions">Functions</h2>
4747
<dl>
48+
<dt id="slack_bolt.adapter.socket_mode.internals.build_headers"><code class="name flex">
49+
<span>def <span class="ident">build_headers</span></span>(<span>req: slack_sdk.socket_mode.request.SocketModeRequest) ‑> Dict[str, str | Sequence[str]] | None</span>
50+
</code></dt>
51+
<dd>
52+
<details class="source">
53+
<summary>
54+
<span>Expand source code</span>
55+
</summary>
56+
<pre><code class="python">def build_headers(req: SocketModeRequest) -&gt; Optional[Dict[str, Union[str, Sequence[str]]]]:
57+
# Mirror the HTTP mode retry headers so middleware/listeners can detect Events API retries
58+
headers: Dict[str, Union[str, Sequence[str]]] = {}
59+
if req.retry_attempt is not None:
60+
headers[&#34;x-slack-retry-num&#34;] = str(req.retry_attempt)
61+
if req.retry_reason is not None:
62+
headers[&#34;x-slack-retry-reason&#34;] = req.retry_reason
63+
return headers or None</code></pre>
64+
</details>
65+
<div class="desc"></div>
66+
</dd>
4867
<dt id="slack_bolt.adapter.socket_mode.internals.run_bolt_app"><code class="name flex">
4968
<span>def <span class="ident">run_bolt_app</span></span>(<span>app: <a title="slack_bolt.app.app.App" href="../../app/app.html#slack_bolt.app.app.App">App</a>,<br>req: slack_sdk.socket_mode.request.SocketModeRequest)</span>
5069
</code></dt>
@@ -54,7 +73,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
5473
<span>Expand source code</span>
5574
</summary>
5675
<pre><code class="python">def run_bolt_app(app: App, req: SocketModeRequest):
57-
bolt_req: BoltRequest = BoltRequest(mode=&#34;socket_mode&#34;, body=req.payload)
76+
bolt_req: BoltRequest = BoltRequest(mode=&#34;socket_mode&#34;, body=req.payload, headers=build_headers(req))
5877
bolt_resp: BoltResponse = app.dispatch(bolt_req)
5978
return bolt_resp</code></pre>
6079
</details>
@@ -111,6 +130,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
111130
</li>
112131
<li><h3><a href="#header-functions">Functions</a></h3>
113132
<ul class="">
133+
<li><code><a title="slack_bolt.adapter.socket_mode.internals.build_headers" href="#slack_bolt.adapter.socket_mode.internals.build_headers">build_headers</a></code></li>
114134
<li><code><a title="slack_bolt.adapter.socket_mode.internals.run_bolt_app" href="#slack_bolt.adapter.socket_mode.internals.run_bolt_app">run_bolt_app</a></code></li>
115135
<li><code><a title="slack_bolt.adapter.socket_mode.internals.send_response" href="#slack_bolt.adapter.socket_mode.internals.send_response">send_response</a></code></li>
116136
</ul>

docs/reference/adapter/wsgi/handler.html

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,20 @@ <h2 class="section-title" id="header-classes">Classes</h2>
117117

118118
def __call__(
119119
self,
120-
environ: Dict[str, Any],
121-
start_response: Callable[[str, List[Tuple[str, str]]], None],
120+
environ: &#34;WSGIEnvironment&#34;,
121+
start_response: &#34;StartResponse&#34;,
122122
) -&gt; Iterable[bytes]:
123123
request = WsgiHttpRequest(environ)
124-
if &#34;HTTP&#34; in request.protocol:
124+
if request.protocol.startswith(&#34;HTTP&#34;):
125125
response: WsgiHttpResponse = self._get_http_response(
126126
request=request,
127127
)
128-
start_response(response.status, response.get_headers())
129-
return response.get_body()
130-
raise TypeError(f&#34;Unsupported SERVER_PROTOCOL: {request.protocol}&#34;)</code></pre>
128+
else:
129+
response = WsgiHttpResponse(
130+
status=400, headers={&#34;content-type&#34;: [&#34;text/plain;charset=utf-8&#34;]}, body=&#34;Bad Request&#34;
131+
)
132+
start_response(response.status, response.get_headers())
133+
return response.get_body()</code></pre>
131134
</details>
132135
<div class="desc"><p>Setup Bolt as a WSGI web framework, this will make your application compatible with WSGI web servers.
133136
This can be used for production deployments.</p>

0 commit comments

Comments
 (0)