fall back to server after reaching maximum number of retries
Use the HTTP header field: X-Accept-Redirect: off to ask for a direct download from the server.master
parent
39e60a019a
commit
a989987319
19
src/main.c
19
src/main.c
|
@ -61,6 +61,7 @@ struct tip_client {
|
|||
int fd;
|
||||
bool error;
|
||||
bool redirected;
|
||||
bool server_only;
|
||||
struct timeval tv_start, tv_last;
|
||||
const char *payload;
|
||||
};
|
||||
|
@ -400,7 +401,10 @@ static void tip_client_connect_cb(struct ev_loop *loop, struct ev_io *io, int ev
|
|||
case TIP_CLIENT_GET_HEADER:
|
||||
syslog(LOG_INFO, "connected to %s to fetch file %s\n",
|
||||
inet_ntoa(cli->addr.sin_addr), filename);
|
||||
snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n\r\n", filename);
|
||||
if (cli->server_only)
|
||||
snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\nX-Accept-Redirect: off\r\n\r\n", filename);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "GET /%s HTTP/1.1\r\n\r\n", filename);
|
||||
break;
|
||||
case TIP_CLIENT_HEAD_HEADER:
|
||||
syslog(LOG_INFO, "connected to %s to get file size of %s\n",
|
||||
|
@ -581,6 +585,19 @@ int main(int argc, char *argv[])
|
|||
ret = tip_client_request_file(&_cli, addr, filename);
|
||||
} while (ret > 0);
|
||||
|
||||
if (ret < 0) {
|
||||
memset(&_cli, 0, sizeof(_cli));
|
||||
_cli.chunk_offset = chunk_size * k;
|
||||
_cli.fd = fd;
|
||||
_cli.server_only = true;
|
||||
|
||||
do {
|
||||
syslog(LOG_INFO, "Requesting file %s to server only\n", filename);
|
||||
_cli.state = TIP_CLIENT_GET_HEADER;
|
||||
ret = tip_client_request_file(&_cli, addr, filename);
|
||||
} while (ret > 0);
|
||||
}
|
||||
|
||||
if (ret < 0)
|
||||
goto err_max_retries;
|
||||
|
||||
|
|
Loading…
Reference in New Issue