Browse Source

Webdav dumps: simplify

Bastien Sevajol (Algoo) 8 years ago
parent
commit
7932ed92bc
1 changed files with 24 additions and 18 deletions
  1. 24 18
      tracim/tracim/lib/webdav/utils.py

+ 24 - 18
tracim/tracim/lib/webdav/utils.py View File

81
             #                                   "locks: 15",
81
             #                                   "locks: 15",
82
         ]
82
         ]
83
 
83
 
84
-        if self._config.get('dump_requests'):
85
-            # Monkey patching
86
-            old_parseXmlBody = util.parseXmlBody
87
-            def new_parseXmlBody(environ, allowEmpty=False):
88
-                xml = old_parseXmlBody(environ, allowEmpty)
89
-                self._dump_request(environ, xml)
90
-                return xml
91
-            util.parseXmlBody = new_parseXmlBody
84
+        self.last_request_time = '__NOT_SET__'
85
+
86
+        # We disable request content dump for moment
87
+        # if self._config.get('dump_requests'):
88
+        #     # Monkey patching
89
+        #     old_parseXmlBody = util.parseXmlBody
90
+        #     def new_parseXmlBody(environ, allowEmpty=False):
91
+        #         xml = old_parseXmlBody(environ, allowEmpty)
92
+        #         self._dump_request(environ, xml)
93
+        #         return xml
94
+        #     util.parseXmlBody = new_parseXmlBody
92
 
95
 
93
     def __call__(self, environ, start_response):
96
     def __call__(self, environ, start_response):
94
         """"""
97
         """"""
95
         #        srvcfg = environ["wsgidav.config"]
98
         #        srvcfg = environ["wsgidav.config"]
96
         verbose = self._config.get("verbose", 2)
99
         verbose = self._config.get("verbose", 2)
100
+        self.last_request_time = '{0}_{1}'.format(
101
+            datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S'),
102
+            int(round(time.time() * 1000)),
103
+        )
97
 
104
 
98
         method = environ["REQUEST_METHOD"]
105
         method = environ["REQUEST_METHOD"]
99
 
106
 
155
                 if k == k.upper():
162
                 if k == k.upper():
156
                     print("%20s: '%s'" % (k, v), file=self.out)
163
                     print("%20s: '%s'" % (k, v), file=self.out)
157
             print("\n", file=self.out)
164
             print("\n", file=self.out)
165
+            self._dump_request(environ, xml=None)
158
 
166
 
159
         # Intercept start_response
167
         # Intercept start_response
160
         #
168
         #
233
         os.makedirs(dump_to_path, exist_ok=True)
241
         os.makedirs(dump_to_path, exist_ok=True)
234
         dump_file = '{0}/{1}_RESPONSE_{2}.yml'.format(
242
         dump_file = '{0}/{1}_RESPONSE_{2}.yml'.format(
235
             dump_to_path,
243
             dump_to_path,
236
-            '{0}_{1}'.format(
237
-                datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S'),
238
-                int(round(time.time() * 1000)),
239
-            ),
244
+            self.last_request_time,
240
             sub_app_start_response.status[0:3],
245
             sub_app_start_response.status[0:3],
241
         )
246
         )
242
         with open(dump_file, 'w+') as f:
247
         with open(dump_file, 'w+') as f:
243
             dump_content = dict()
248
             dump_content = dict()
249
+            headers = {}
250
+            for header_tuple in sub_app_start_response.response_headers:
251
+                headers[header_tuple[0]] = header_tuple[1]
252
+            dump_content['headers'] = headers
244
             if isinstance(drb, str):
253
             if isinstance(drb, str):
245
                 dump_content['content'] = drb.replace('PROPFIND XML response body:\n', '')
254
                 dump_content['content'] = drb.replace('PROPFIND XML response body:\n', '')
246
 
255
 
254
         os.makedirs(dump_to_path, exist_ok=True)
263
         os.makedirs(dump_to_path, exist_ok=True)
255
         dump_file = '{0}/{1}_REQUEST_{2}.yml'.format(
264
         dump_file = '{0}/{1}_REQUEST_{2}.yml'.format(
256
             dump_to_path,
265
             dump_to_path,
257
-            '{0}_{1}'.format(
258
-                datetime.utcnow().strftime('%Y-%m-%d_%H-%M-%S'),
259
-                int(round(time.time() * 1000)),
260
-            ),
266
+            self.last_request_time,
261
             environ['REQUEST_METHOD'],
267
             environ['REQUEST_METHOD'],
262
         )
268
         )
263
         with open(dump_file, 'w+') as f:
269
         with open(dump_file, 'w+') as f:
264
             dump_content = dict()
270
             dump_content = dict()
265
-            dump_content['path'] = environ['PATH_INFO']
266
-            dump_content['Authorization'] = environ['HTTP_AUTHORIZATION']
271
+            dump_content['path'] = environ.get('PATH_INFO', '')
272
+            dump_content['Authorization'] = environ.get('HTTP_AUTHORIZATION', '')
267
             if xml:
273
             if xml:
268
                 dump_content['content'] = ElementTree.tostring(xml, 'utf-8')
274
                 dump_content['content'] = ElementTree.tostring(xml, 'utf-8')
269
 
275