Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit 8533b47

Browse files
committed
Send redirects for link files
1 parent 67ef7f3 commit 8533b47

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

gitblog.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def handler(req):
7575
'gitblog.max_age_blob': '1800',
7676
'gitblog.max_age_tree': '600',
7777
'gitblog.denied_path': 'private',
78+
'gitblog.redirect_code': 'HTTP_MOVED_PERMANENTLY',
7879
}
7980

8081
for k in config.keys():
@@ -98,6 +99,12 @@ def handler(req):
9899
'max_age_tree']:
99100
config['gitblog.' + c] = int(config['gitblog.' + c])
100101

102+
if not config['gitblog.redirect_code'] in [ \
103+
'HTTP_MOVED_PERMANENTLY',
104+
'HTTP_MOVED_TEMPORARILY',
105+
'HTTP_TEMPORARY_REDIRECT']:
106+
config['gitblog.redirect_code'] = 'HTTP_MOVED_PERMANENTLY'
107+
101108
# Get request path as list
102109
requested_path = req.uri.strip('/').split('/')
103110
requested_path = list(filter(None, requested_path))
@@ -156,7 +163,16 @@ def handler(req):
156163
requested_object.data_stream.read().decode('utf-8'))
157164
requested_path = link_requested_path.strip('/').split('/')
158165
requested_path = list(filter(None, requested_path))
159-
requested_object = git_obj.tree[link_requested_path]
166+
167+
redirect_target = '/'.join(requested_path)
168+
# TODO: Moved protocol values for verfication
169+
# to program parameters
170+
if not redirect_target[0:7] == 'http://' and \
171+
not redirect_target[0:8] == 'https://':
172+
redirect_target = '/' + redirect_target
173+
174+
req.headers_out.add('Location', redirect_target)
175+
return(getattr(apache, config['gitblog.redirect_code']))
160176
except:
161177
return(apache.HTTP_NOT_FOUND)
162178

0 commit comments

Comments
 (0)