@@ -111,7 +111,7 @@ def __on(self, event, callback):
111111 self .callbacks [event ] = callback
112112 if len (self .subscriptions [event ]) == 0 :
113113 # session_subscribe(self.conn, event, self.__handle_event)
114- self .conn .add_callback (event , self .__handle_event )
114+ return self .conn .add_callback (event , self .__handle_event )
115115
116116 def __handle_event (self , event , data ):
117117 """Perform callback function on event."""
@@ -156,8 +156,9 @@ def callback_on_url_match(data):
156156 body = data ['request' ].get ('body' , None )
157157 request = Request (request_id , url , method , headers , body , self )
158158 callback (request )
159- self .__on ('before_request' , callback_on_url_match )
160- self .callbacks [request_id ] = callback
159+ callback_id = self .__on ('before_request' , callback_on_url_match )
160+ request_id = callback_id
161+ self .callbacks [callback_id ] = callback
161162 if 'before_request' not in self .subscriptions or not self .subscriptions .get ('before_request' ):
162163 self .subscriptions ['before_request' ] = [request_id ]
163164 else :
@@ -198,8 +199,9 @@ def callback_on_url_match(data):
198199 headers = data ['response' ].get ('headers' , {})
199200 response = Response (request_id , url , status_code , headers , body , self )
200201 callback (response )
201- self .__on ('response_started' , callback_on_url_match )
202- self .callbacks [request_id ] = callback
202+ callback_id = self .__on ('response_started' , callback_on_url_match )
203+ request_id = callback_id
204+ self .callbacks [callback_id ] = callback
203205 if 'response_started' not in self .subscriptions or not self .subscriptions .get ('response_started' ):
204206 self .subscriptions ['response_started' ] = [request_id ]
205207 else :
0 commit comments