Show More
@@ -1,64 +1,64 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-2019 RhodeCode GmbH |
|
2 | # Copyright (C) 2014-2019 RhodeCode 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 | import gc |
|
|||
19 | import time |
|
18 | import time | |
20 | import logging |
|
19 | import logging | |
21 |
|
20 | |||
22 |
|
21 | import vcsserver | ||
23 | from vcsserver.utils import safe_str |
|
22 | from vcsserver.utils import safe_str | |
24 |
|
23 | |||
25 |
|
24 | |||
26 | log = logging.getLogger(__name__) |
|
25 | log = logging.getLogger(__name__) | |
27 |
|
26 | |||
28 |
|
27 | |||
29 | def get_access_path(request): |
|
28 | def get_access_path(request): | |
30 | environ = request.environ |
|
29 | environ = request.environ | |
31 | return environ.get('PATH_INFO') |
|
30 | return environ.get('PATH_INFO') | |
32 |
|
31 | |||
33 |
|
32 | |||
34 | def get_user_agent(environ): |
|
33 | def get_user_agent(environ): | |
35 | return environ.get('HTTP_USER_AGENT') |
|
34 | return environ.get('HTTP_USER_AGENT') | |
36 |
|
35 | |||
37 |
|
36 | |||
38 | class RequestWrapperTween(object): |
|
37 | class RequestWrapperTween(object): | |
39 | def __init__(self, handler, registry): |
|
38 | def __init__(self, handler, registry): | |
40 | self.handler = handler |
|
39 | self.handler = handler | |
41 | self.registry = registry |
|
40 | self.registry = registry | |
42 |
|
41 | |||
43 | # one-time configuration code goes here |
|
42 | # one-time configuration code goes here | |
44 |
|
43 | |||
45 | def __call__(self, request): |
|
44 | def __call__(self, request): | |
46 | start = time.time() |
|
45 | start = time.time() | |
47 | try: |
|
46 | try: | |
48 | response = self.handler(request) |
|
47 | response = self.handler(request) | |
49 | finally: |
|
48 | finally: | |
50 | end = time.time() |
|
49 | end = time.time() | |
51 | total = end - start |
|
50 | total = end - start | |
52 | count = request.request_count() |
|
51 | count = request.request_count() | |
|
52 | _ver_ = vcsserver.__version__ | |||
53 | log.info( |
|
53 | log.info( | |
54 | 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s]', |
|
54 | 'Req[%4s] IP: %s %s Request to %s time: %.4fs [%s], VCSServer %s', | |
55 | count, '127.0.0.1', request.environ.get('REQUEST_METHOD'), |
|
55 | count, '127.0.0.1', request.environ.get('REQUEST_METHOD'), | |
56 | safe_str(get_access_path(request)), total, get_user_agent(request.environ)) |
|
56 | safe_str(get_access_path(request)), total, get_user_agent(request.environ), _ver_) | |
57 |
|
57 | |||
58 | return response |
|
58 | return response | |
59 |
|
59 | |||
60 |
|
60 | |||
61 | def includeme(config): |
|
61 | def includeme(config): | |
62 | config.add_tween( |
|
62 | config.add_tween( | |
63 | 'vcsserver.tweens.request_wrapper.RequestWrapperTween', |
|
63 | 'vcsserver.tweens.request_wrapper.RequestWrapperTween', | |
64 | ) |
|
64 | ) |
General Comments 0
You need to be logged in to leave comments.
Login now