mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-15 08:04:49 +01:00
rewrite: rewrite rel urls to rel urls, both server and wombat side #123
This commit is contained in:
parent
43716f5f1d
commit
a2a2a054a0
@ -21,10 +21,10 @@
|
||||
|
||||
# UrlRewriter tests
|
||||
>>> do_rewrite('other.html', '20131010/http://example.com/path/page.html', 'https://web.archive.org/web/')
|
||||
'https://web.archive.org/web/20131010/http://example.com/path/other.html'
|
||||
'/web/20131010/http://example.com/path/other.html'
|
||||
|
||||
>>> do_rewrite('file.js', '20131010/http://example.com/path/page.html', 'https://web.archive.org/web/', 'js_')
|
||||
'https://web.archive.org/web/20131010js_/http://example.com/path/file.js'
|
||||
'/web/20131010js_/http://example.com/path/file.js'
|
||||
|
||||
>>> do_rewrite('file.js', '20131010/http://example.com/', '/coll/')
|
||||
'/coll/20131010/http://example.com/file.js'
|
||||
@ -35,6 +35,9 @@
|
||||
>>> do_rewrite('file.js', '20131010/http://example.com', '/coll/', '')
|
||||
'/coll/20131010/http://example.com/file.js'
|
||||
|
||||
>>> do_rewrite('/other.html', '20130907*/http://example.com/path/page.html', 'http://localhost:8080/coll/')
|
||||
'/coll/20130907*/http://example.com/other.html'
|
||||
|
||||
>>> do_rewrite('/other.html', '20130907*/http://example.com/path/page.html', '/coll/')
|
||||
'/coll/20130907*/http://example.com/other.html'
|
||||
|
||||
|
@ -30,6 +30,7 @@ class UrlRewriter(object):
|
||||
self.prefix_scheme = self.full_prefix.split(':')[0]
|
||||
else:
|
||||
self.prefix_scheme = None
|
||||
self.prefix_abs = self.prefix and self.prefix.startswith(self.PROTOCOLS)
|
||||
self.cookie_scope = cookie_scope
|
||||
self.rewrite_opts = rewrite_opts
|
||||
|
||||
@ -74,8 +75,15 @@ class UrlRewriter(object):
|
||||
mod = wburl.mod
|
||||
|
||||
final_url = self.prefix + wburl.to_str(mod=mod, url=new_url)
|
||||
|
||||
if not is_abs and self.prefix_abs and not self.rewrite_opts.get('no_match_rel'):
|
||||
parts = final_url.split('/', 3)
|
||||
final_url = '/'
|
||||
if len(parts) == 4:
|
||||
final_url += parts[3]
|
||||
|
||||
# experiment for setting scheme rel url
|
||||
if scheme_rel and self.prefix.startswith(self.PROTOCOLS):
|
||||
elif scheme_rel and self.prefix_abs:
|
||||
final_url = final_url.split(':', 1)[1]
|
||||
|
||||
return final_url
|
||||
|
@ -143,7 +143,7 @@ var wombat_internal = function($wbwindow) {
|
||||
var URL_PROPS = ["href", "hash", "pathname", "host", "hostname", "protocol", "origin", "search", "port"];
|
||||
|
||||
//============================================
|
||||
function rewrite_url_(url) {
|
||||
function rewrite_url_(url, use_rel) {
|
||||
// If undefined, just return it
|
||||
if (!url) {
|
||||
return url;
|
||||
@ -215,7 +215,7 @@ var wombat_internal = function($wbwindow) {
|
||||
return url;
|
||||
}
|
||||
|
||||
return wb_replay_date_prefix + wb_orig_origin + url;
|
||||
return (use_rel ? wb_coll_prefix : wb_replay_date_prefix) + wb_orig_origin + url;
|
||||
}
|
||||
|
||||
// If full url starting with http://, https:// or //
|
||||
@ -235,7 +235,6 @@ var wombat_internal = function($wbwindow) {
|
||||
}
|
||||
|
||||
var curr_scheme = orig_protocol + '//';
|
||||
var host = orig_host + '/';
|
||||
var path = url.substring(prefix_host.length);
|
||||
var rebuild = false;
|
||||
|
||||
@ -251,7 +250,12 @@ var wombat_internal = function($wbwindow) {
|
||||
}
|
||||
|
||||
if (rebuild) {
|
||||
url = curr_scheme + host + path;
|
||||
if (!use_rel) {
|
||||
url = curr_scheme + orig_host;
|
||||
} else {
|
||||
url = "";
|
||||
}
|
||||
url += "/" + path;
|
||||
}
|
||||
|
||||
return url;
|
||||
@ -451,7 +455,8 @@ var wombat_internal = function($wbwindow) {
|
||||
value = this._parser[prop];
|
||||
} else {
|
||||
prop = "href";
|
||||
value = rewrite_url(this._parser.href);
|
||||
var rel = (value == this._parser.pathname);
|
||||
value = rewrite_url(this._parser.href, rel);
|
||||
}
|
||||
|
||||
orig_setter.call(this, prop, value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user