mirror of
https://github.com/xroche/httrack.git
synced 2026-07-11 19:36:52 +03:00
Compare commits
1 Commits
fix-x32-ll
...
fix-176-up
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5b05c163c |
@@ -3540,22 +3540,20 @@ void back_wait(struct_back * sback, httrackp * opt, cache_back * cache,
|
||||
if (back[i].r.statuscode == 406) { // 'Not Acceptable'
|
||||
back[i].r.statuscode = HTTP_OK;
|
||||
}
|
||||
// 'do not erase already downloaded file'
|
||||
// on an updated file
|
||||
// with an error : consider a 304 error
|
||||
if (!opt->delete_old) {
|
||||
if (HTTP_IS_ERROR(back[i].r.statuscode) && back[i].is_update
|
||||
&& !back[i].testmode) {
|
||||
if (back[i].url_sav[0] && fexist_utf8(back[i].url_sav)) {
|
||||
hts_log_print(opt, LOG_DEBUG,
|
||||
"Error ignored %d (%s) because of 'no purge' option for %s%s",
|
||||
back[i].r.statuscode, back[i].r.msg,
|
||||
back[i].url_adr, back[i].url_fil);
|
||||
back[i].r.statuscode = HTTP_NOT_MODIFIED;
|
||||
deletehttp(&back[i].r);
|
||||
back[i].r.soc = INVALID_SOCKET;
|
||||
}
|
||||
}
|
||||
// On update, keep the good copy on error (mask as 304); skip
|
||||
// resume paths so a stale-partial 416 still re-fetches.
|
||||
if (HTTP_IS_ERROR(back[i].r.statuscode) &&
|
||||
back[i].is_update && !back[i].testmode &&
|
||||
back[i].range_req_size == 0 && back[i].url_sav[0] &&
|
||||
fexist_utf8(back[i].url_sav)) {
|
||||
hts_log_print(opt, LOG_DEBUG,
|
||||
"Error %d (%s) ignored on update, keeping "
|
||||
"existing copy: %s%s",
|
||||
back[i].r.statuscode, back[i].r.msg,
|
||||
back[i].url_adr, back[i].url_fil);
|
||||
back[i].r.statuscode = HTTP_NOT_MODIFIED;
|
||||
deletehttp(&back[i].r);
|
||||
back[i].r.soc = INVALID_SOCKET;
|
||||
}
|
||||
// Various hacks to limit re-transfers when updating a mirror
|
||||
// Force update if same size detected
|
||||
|
||||
11
tests/44_local-update-errormask.test
Normal file
11
tests/44_local-update-errormask.test
Normal file
@@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
# Issue #176: on --update a page that 200'd on the first crawl but now 403s must
|
||||
# keep its good local copy, not be overwritten by the error body nor purged.
|
||||
set -euo pipefail
|
||||
|
||||
: "${top_srcdir:=..}"
|
||||
|
||||
bash "$top_srcdir/tests/local-crawl.sh" --rerun \
|
||||
--found 'errmask/keep.dat' \
|
||||
--file-min-bytes 'errmask/keep.dat' 1024 \
|
||||
httrack 'BASEURL/errmask/index.html'
|
||||
@@ -112,6 +112,7 @@ TESTS = \
|
||||
40_local-why.test \
|
||||
41_local-utf8-link.test \
|
||||
42_local-maxsize-slow.test \
|
||||
43_local-update-truncate.test
|
||||
43_local-update-truncate.test \
|
||||
44_local-update-errormask.test
|
||||
|
||||
CLEANFILES = check-network_sh.cache
|
||||
|
||||
@@ -934,6 +934,33 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
def route_mini304_page(self):
|
||||
self.big_send(b"<html><body>tiny cacheable page</body></html>\n", "text/html")
|
||||
|
||||
# --- /errmask/: issue #176 — a page that 200'd on the first crawl but 403s
|
||||
# on the update fetch must keep its good copy, not be overwritten nor purged.
|
||||
ERRMASK_GOOD = b"KEEP" + b"." * 1020 # 1024 B distinctive non-HTML body
|
||||
ERRMASK_ERR = b"<html><body>error 403</body></html>\n"
|
||||
|
||||
def route_errmask_index(self):
|
||||
self.send_html('\t<a href="keep.dat">keep</a>\n')
|
||||
|
||||
def route_errmask_keep(self):
|
||||
# First crawl (no validator) gets the 1024 B body + Last-Modified; the
|
||||
# update sends a conditional and gets a 403 error page.
|
||||
if self.headers.get("If-Modified-Since") or self.headers.get("If-None-Match"):
|
||||
self.send_response(403, "Forbidden")
|
||||
self.send_header("Content-Type", "text/html")
|
||||
self.send_header("Content-Length", str(len(self.ERRMASK_ERR)))
|
||||
self.end_headers()
|
||||
if self.command != "HEAD":
|
||||
self.wfile.write(self.ERRMASK_ERR)
|
||||
return
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/octet-stream")
|
||||
self.send_header("Last-Modified", BIG_LASTMOD)
|
||||
self.send_header("Content-Length", str(len(self.ERRMASK_GOOD)))
|
||||
self.end_headers()
|
||||
if self.command != "HEAD":
|
||||
self.wfile.write(self.ERRMASK_GOOD)
|
||||
|
||||
# --- delayed-type degenerate paths (issues #5/#107) --------------------
|
||||
def route_delayed_index(self):
|
||||
self.send_html(
|
||||
@@ -1177,6 +1204,8 @@ class Handler(SimpleHTTPRequestHandler):
|
||||
"/redir/target.html": route_redir_target,
|
||||
"/mini304/index.html": route_mini304_index,
|
||||
"/mini304/page.html": route_mini304_page,
|
||||
"/errmask/index.html": route_errmask_index,
|
||||
"/errmask/keep.dat": route_errmask_keep,
|
||||
}
|
||||
|
||||
# --- /big/ seeded pseudo-site ------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user