Show More
@@ -1,60 +1,60 b'' | |||||
1 | # RhodeCode VCSServer provides access to different vcs backends via network. |
|
1 | # RhodeCode VCSServer provides access to different vcs backends via network. | |
2 | # Copyright (C) 2014-2017 RodeCode GmbH |
|
2 | # Copyright (C) 2014-2017 RodeCode GmbH | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or modify |
|
4 | # This program is free software; you can redistribute it and/or modify | |
5 | # it under the terms of the GNU General Public License as published by |
|
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 3 of the License, or |
|
6 | # the Free Software Foundation; either version 3 of the License, or | |
7 | # (at your option) any later version. |
|
7 | # (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software Foundation, |
|
15 | # along with this program; if not, write to the Free Software Foundation, | |
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
16 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 |
|
17 | |||
18 |
|
18 | |||
19 |
|
19 | |||
20 | import time |
|
20 | import time | |
21 | import logging |
|
21 | import logging | |
22 |
|
22 | |||
23 |
|
23 | |||
24 | from vcsserver.utils import safe_str |
|
24 | from vcsserver.utils import safe_str | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | log = logging.getLogger(__name__) |
|
27 | log = logging.getLogger(__name__) | |
28 |
|
28 | |||
29 |
|
29 | |||
30 | def get_access_path(request): |
|
30 | def get_access_path(request): | |
31 | environ = request.environ |
|
31 | environ = request.environ | |
32 | return environ.get('PATH_INFO') |
|
32 | return environ.get('PATH_INFO') | |
33 |
|
33 | |||
34 |
|
34 | |||
35 | class RequestWrapperTween(object): |
|
35 | class RequestWrapperTween(object): | |
36 | def __init__(self, handler, registry): |
|
36 | def __init__(self, handler, registry): | |
37 | self.handler = handler |
|
37 | self.handler = handler | |
38 | self.registry = registry |
|
38 | self.registry = registry | |
39 |
|
39 | |||
40 | # one-time configuration code goes here |
|
40 | # one-time configuration code goes here | |
41 |
|
41 | |||
42 | def __call__(self, request): |
|
42 | def __call__(self, request): | |
43 | start = time.time() |
|
43 | start = time.time() | |
44 | try: |
|
44 | try: | |
45 | response = self.handler(request) |
|
45 | response = self.handler(request) | |
46 | finally: |
|
46 | finally: | |
47 | end = time.time() |
|
47 | end = time.time() | |
48 |
|
48 | |||
49 | log.info('IP: %s Request to %s time: %.3fs' % ( |
|
49 | log.info('IP: %s Request to path: `%s` time: %.3fs' % ( | |
50 | '127.0.0.1', |
|
50 | '127.0.0.1', | |
51 | safe_str(get_access_path(request)), end - start) |
|
51 | safe_str(get_access_path(request)), end - start) | |
52 | ) |
|
52 | ) | |
53 |
|
53 | |||
54 | return response |
|
54 | return response | |
55 |
|
55 | |||
56 |
|
56 | |||
57 | def includeme(config): |
|
57 | def includeme(config): | |
58 | config.add_tween( |
|
58 | config.add_tween( | |
59 | 'vcsserver.tweens.RequestWrapperTween', |
|
59 | 'vcsserver.tweens.RequestWrapperTween', | |
60 | ) |
|
60 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now