initial support for capturing bytes read from gateway response
[OpenSRF.git] / src / python / osrf / gateway.py
index 11776a4..a71d02d 100644 (file)
@@ -13,6 +13,7 @@ class GatewayRequest:
         self.method = method
         self.params = params
         self.path = 'gateway'
+        self.bytes_read = 0 # for now this, this is really characters read
 
     def setPath(self, path):
         self.path = path
@@ -62,8 +63,11 @@ class JSONGatewayRequest(GatewayRequest):
         return self.getFormat()
 
     def handleResponse(self, response):
-        s = response.read()
-        obj = to_object(s)
+
+        data = response.read()
+        self.bytes_read = len(str(response.headers)) + len(data)
+        obj = to_object(data)
+
         if obj['status'] != 200:
             sys.stderr.write('JSON gateway returned status %d:\n%s\n' % (obj['status'], s))
             return None