mirror of
				https://github.com/django/daphne.git
				synced 2025-11-01 00:07:26 +03:00 
			
		
		
		
	Add channel to every consumer signature, update msg fmt docs
This commit is contained in:
		
							parent
							
								
									c2c1ffc5bd
								
							
						
					
					
						commit
						5a7af1e3af
					
				|  | @ -15,7 +15,7 @@ class UrlConsumer(object): | |||
|         self.handler = BaseHandler() | ||||
|         self.handler.load_middleware() | ||||
| 
 | ||||
|     def __call__(self, **kwargs): | ||||
|     def __call__(self, channel, **kwargs): | ||||
|         request = HttpRequest.channel_decode(kwargs) | ||||
|         try: | ||||
|             response = self.handler.get_response(request) | ||||
|  | @ -42,7 +42,7 @@ def view_consumer(channel_name, alias=None): | |||
|     """ | ||||
|     def inner(func):  | ||||
|         @functools.wraps(func) | ||||
|         def consumer(**kwargs): | ||||
|         def consumer(channel, **kwargs): | ||||
|             request = HttpRequest.channel_decode(kwargs) | ||||
|             response = func(request) | ||||
|             Channel(request.response_channel).send(**response.channel_encode()) | ||||
|  |  | |||
|  | @ -15,8 +15,9 @@ class BaseChannelBackend(object): | |||
|     registry of consumers. | ||||
|     """ | ||||
| 
 | ||||
|     def __init__(self): | ||||
|     def __init__(self, expiry=60): | ||||
|         self.registry = ConsumerRegistry() | ||||
|         self.expiry = expiry | ||||
| 
 | ||||
|     def send(self, channel, message): | ||||
|         """ | ||||
|  |  | |||
|  | @ -4,20 +4,78 @@ Message Standards | |||
| Some standardised message formats are used for common message types - they | ||||
| are detailed below. | ||||
| 
 | ||||
| Note: All consumers also receive the channel name as the keyword argument | ||||
| "channel", so there is no need for separate type information to let | ||||
| multi-channel consumers distinguish. | ||||
| 
 | ||||
| HTTP Request | ||||
| ------------ | ||||
| 
 | ||||
| Represents a full-fledged, single HTTP request coming in from a client. | ||||
| 
 | ||||
| Contains the following keys: | ||||
| 
 | ||||
| * request: An encoded Django HTTP request | ||||
| * response_channel: The channel name to write responses to | ||||
| * GET: List of (key, value) tuples of GET variables | ||||
| * POST: List of (key, value) tuples of POST variables | ||||
| * COOKIES: Same as  ``request.COOKIES`` | ||||
| * META: Same as  ``request.META`` | ||||
| * path: Same as  ``request.path`` | ||||
| * path_info: Same as  ``request.path_info`` | ||||
| * method: Upper-cased HTTP method | ||||
| * response_channel: Channel name to write response to | ||||
| 
 | ||||
| 
 | ||||
| HTTP Response | ||||
| ------------- | ||||
| 
 | ||||
| Sends a whole response to a client. | ||||
| 
 | ||||
| Contains the following keys: | ||||
| 
 | ||||
| * response: An encoded Django HTTP response | ||||
| * content: String of content to send | ||||
| * content_type: Mimetype of content | ||||
| * status_code: Numerical HTTP status code | ||||
| * headers: Dictionary of headers (key is header name, value is value) | ||||
| 
 | ||||
| 
 | ||||
| HTTP Disconnect | ||||
| --------------- | ||||
| 
 | ||||
| Send when a client disconnects early, before the response has been sent. | ||||
| Only sent by long-polling-capable HTTP interface servers. | ||||
| 
 | ||||
| Contains the same keys as HTTP Request. | ||||
| 
 | ||||
| 
 | ||||
| WebSocket Connection | ||||
| -------------------- | ||||
| 
 | ||||
| Sent when a new WebSocket is connected. | ||||
| 
 | ||||
| Contains the following keys: | ||||
| 
 | ||||
| * GET: List of (key, value) tuples of GET variables | ||||
| * COOKIES: Same as ``request.COOKIES`` | ||||
| * META: Same as ``request.META`` | ||||
| * path: Same as ``request.path`` | ||||
| * path_info: Same as  ``request.path_info`` | ||||
| * send_channel: Channel name to send responses on | ||||
| 
 | ||||
| 
 | ||||
| WebSocket Receive | ||||
| ----------------- | ||||
| 
 | ||||
| Sent when a datagram is received on the WebSocket. | ||||
| 
 | ||||
| Contains the same keys as WebSocket Connection, plus: | ||||
| 
 | ||||
| * content: String content of the datagram | ||||
| 
 | ||||
| 
 | ||||
| WebSocket Close | ||||
| --------------- | ||||
| 
 | ||||
| Sent when the WebSocket is closed by either the client or the server. | ||||
| 
 | ||||
| Contains the same keys as WebSocket Connection, including send_channel, | ||||
| though nothing should be sent on it. | ||||
|  |  | |||
|  | @ -16,4 +16,4 @@ class Worker(object): | |||
|         while True: | ||||
|             channel, message = self.channel_layer.receive_many(channels) | ||||
|             consumer = self.channel_layer.registry.consumer_for_channel(channel) | ||||
|             consumer(**message) | ||||
|             consumer(channel=channel, **message) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user