vcs: Add custom response header 'X-RhodeCode-Backend' to indicate VCS responses and which backend is in use.

This commit is contained in:
Martin Bornhold 2016-08-09 16:03:14 +02:00
parent 0015204e38
commit 1b6f04f8b6
2 changed files with 15 additions and 4 deletions

View file

@ -79,12 +79,18 @@ class SimpleSvnApp(object):
return headers
def _get_response_headers(self, headers):
return [
headers = [
(h, headers[h])
for h in headers
if h.lower() not in self.IGNORED_HEADERS
]
# Add custom response header to indicate that this is a VCS response
# and which backend is used.
headers.append(('X-RhodeCode-Backend', 'svn'))
return headers
class SimpleSvn(simplevcs.SimpleVCS):

View file

@ -39,12 +39,12 @@ log = logging.getLogger(__name__)
def create_git_wsgi_app(repo_path, repo_name, config):
url = _vcs_streaming_url() + 'git/'
return VcsHttpProxy(url, repo_path, repo_name, config)
return VcsHttpProxy(url, repo_path, repo_name, config, 'git')
def create_hg_wsgi_app(repo_path, repo_name, config):
url = _vcs_streaming_url() + 'hg/'
return VcsHttpProxy(url, repo_path, repo_name, config)
return VcsHttpProxy(url, repo_path, repo_name, config, 'hg')
def _vcs_streaming_url():
@ -67,7 +67,7 @@ class VcsHttpProxy(object):
server as well.
"""
def __init__(self, url, repo_path, repo_name, config):
def __init__(self, url, repo_path, repo_name, config, backend):
"""
:param str url: The URL of the VCSServer to call.
"""
@ -75,6 +75,7 @@ class VcsHttpProxy(object):
self._repo_name = repo_name
self._repo_path = repo_path
self._config = config
self._backend = backend
log.debug(
"Creating VcsHttpProxy for repo %s, url %s",
repo_name, url)
@ -115,6 +116,10 @@ class VcsHttpProxy(object):
if not wsgiref.util.is_hop_by_hop(h)
]
# Add custom response header to indicate that this is a VCS response
# and which backend is used.
response_headers.append(('X-RhodeCode-Backend', self._backend))
# TODO: johbo: Better way to get the status including text?
status = str(response.status_code)
start_response(status, response_headers)