@@ -75,6 +75,7 @@ def handler(req):
75
75
'gitblog.max_age_blob' : '1800' ,
76
76
'gitblog.max_age_tree' : '600' ,
77
77
'gitblog.denied_path' : 'private' ,
78
+ 'gitblog.redirect_code' : 'HTTP_MOVED_PERMANENTLY' ,
78
79
}
79
80
80
81
for k in config .keys ():
@@ -98,6 +99,12 @@ def handler(req):
98
99
'max_age_tree' ]:
99
100
config ['gitblog.' + c ] = int (config ['gitblog.' + c ])
100
101
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
+
101
108
# Get request path as list
102
109
requested_path = req .uri .strip ('/' ).split ('/' )
103
110
requested_path = list (filter (None , requested_path ))
@@ -156,7 +163,16 @@ def handler(req):
156
163
requested_object .data_stream .read ().decode ('utf-8' ))
157
164
requested_path = link_requested_path .strip ('/' ).split ('/' )
158
165
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' ]))
160
176
except :
161
177
return (apache .HTTP_NOT_FOUND )
162
178
0 commit comments