Skip to content

Commit 35a2139

Browse files
mattiasrungefangfufu
authored andcommitted
Fix for single file mode not working
- Fix for not sending ranges which exceed the content-length which will result in an error. - Fix for byte range being set to 1 byte too large, it should be the end index, not the size as described in https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests
1 parent 595c6d2 commit 35a2139

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/link.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,8 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
799799
if (!next_table) {
800800
if (CONFIG.mode == NORMAL) {
801801
next_table = LinkTable_new(tmp_link->f_url);
802+
} else if (CONFIG.mode == SINGLE) {
803+
next_table = single_LinkTable_new(tmp_link->f_url);
802804
} else if (CONFIG.mode == SONIC) {
803805
if (!CONFIG.sonic_id3) {
804806
next_table = sonic_LinkTable_new_index(tmp_link->sonic.id);
@@ -808,7 +810,7 @@ LinkTable *path_to_Link_LinkTable_new(const char *path)
808810
tmp_link->sonic.id);
809811
}
810812
} else {
811-
lprintf(fatal, "Invalid CONFIG.mode\n");
813+
lprintf(fatal, "Invalid CONFIG.mode: %d\n", CONFIG.mode);
812814
}
813815
}
814816
if (link) {
@@ -981,7 +983,7 @@ static CURL *Link_download_curl_setup(Link *link, size_t req_size, off_t offset,
981983
}
982984

983985
size_t start = offset;
984-
size_t end = start + req_size;
986+
size_t end = start + req_size - 1;
985987

986988
char range_str[64];
987989
snprintf(range_str, sizeof(range_str), "%lu-%lu", start, end);
@@ -1061,6 +1063,11 @@ long Link_download(Link *link, char *output_buf, size_t req_size, off_t offset)
10611063
header.curr_size = 0;
10621064
header.data = NULL;
10631065

1066+
if (offset + req_size > link->content_length) {
1067+
lprintf(error, "requested size to large, req_size: %lu, recv: %ld, content-length: %ld\n", req_size, recv, link->content_length);
1068+
req_size = link->content_length - offset;
1069+
}
1070+
10641071
CURL *curl = Link_download_curl_setup(link, req_size, offset, &header, &ts);
10651072

10661073
transfer_blocking(curl);
@@ -1096,7 +1103,7 @@ long path_download(const char *path, char *output_buf, size_t req_size,
10961103
return Link_download(link, output_buf, req_size, offset);
10971104
}
10981105

1099-
static void make_link_relative(const char *page_url, char *link_url)
1106+
static void make_link_relative(const char *page_url, char *link_url)
11001107
{
11011108
/*
11021109
Some servers make the links to subdirectories absolute (in URI terms:

0 commit comments

Comments
 (0)