Skip to content

Commit d2af5e5

Browse files
committed
remove handler, add the neccesary comments and remove the extra part
1 parent 99b532b commit d2af5e5

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

channels/generic/http.py

+18-17
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,17 @@
77
from ..exceptions import StopConsumer
88

99
logger = logging.getLogger("channels.consumer")
10-
if not logger.hasHandlers():
11-
handler = logging.StreamHandler()
12-
formatter = logging.Formatter(
13-
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
14-
)
15-
handler.setFormatter(formatter)
16-
logger.addHandler(handler)
17-
logger.setLevel(logging.DEBUG)
10+
logger.setLevel(logging.DEBUG)
1811

1912

2013
class AsyncHttpConsumer(AsyncConsumer):
2114
"""
2215
Async HTTP consumer. Provides basic primitives for building asynchronous
2316
HTTP endpoints.
17+
18+
Note that the ASGI spec requires that the protocol server only starts
19+
sending the response to the client after ``self.send_body`` has been
20+
called the first time.
2421
"""
2522

2623
def __init__(self, *args, **kwargs):
@@ -43,6 +40,10 @@ async def send_headers(self, *, status=200, headers=None):
4340
async def send_body(self, body, *, more_body=False):
4441
"""
4542
Sends a response body to the client. The method expects a bytestring.
43+
44+
Set ``more_body=True`` if you want to send more body content later.
45+
The default behavior closes the response, and further messages on
46+
the channel will be ignored.
4647
"""
4748
assert isinstance(body, bytes), "Body is not bytes"
4849
await self.send(
@@ -51,14 +52,18 @@ async def send_body(self, body, *, more_body=False):
5152

5253
async def send_response(self, status, body, **kwargs):
5354
"""
54-
Sends a response to the client.
55+
Sends a response to the client. This is a thin wrapper over
56+
``self.send_headers`` and ``self.send_body``, and everything said
57+
above applies here as well. This method may only be called once.
5558
"""
5659
await self.send_headers(status=status, **kwargs)
5760
await self.send_body(body)
5861

5962
async def handle(self, body):
6063
"""
61-
Receives the request body as a bytestring.
64+
Receives the request body as a bytestring. Response may be composed
65+
using the ``self.send*`` methods; the return value of this method is
66+
thrown away.
6267
"""
6368
raise NotImplementedError(
6469
"Subclasses of AsyncHttpConsumer must provide a handle() method."
@@ -94,10 +99,6 @@ async def http_disconnect(self, message):
9499
"""
95100
Let the user do their cleanup and close the consumer.
96101
"""
97-
try:
98-
await self.disconnect()
99-
await aclose_old_connections()
100-
except Exception as e:
101-
logger.error(f"Error during disconnect: {str(e)}")
102-
finally:
103-
raise StopConsumer()
102+
await self.disconnect()
103+
await aclose_old_connections()
104+
raise StopConsumer()

0 commit comments

Comments
 (0)