Skip to content
Snippets Groups Projects
Commit e9778331 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix a bunch of false "File sent" logs (and uploader-notifications)

Web browsers tend start a download and then immediately close the socket
(so now send_failed will be true), while on a secondary socket, do a range
download of the same file.

So log the range requests/completions and don't log successful file sends
when the send was terminated due to a send failure.

We still count very small (e.g. 2 byte) ranges as successful file transfers
and notify the uploader (of a partial download), so we should fix those
issues still. But at least now, there's a whole lot less "noise" created
from HTTP[S} file downloads via browser.
parent d6293e05
No related branches found
No related tags found
No related merge requests found
Pipeline #6175 passed
......@@ -256,7 +256,8 @@ typedef struct {
char host_ip[INET6_ADDRSTRLEN];
char host_name[128]; /* Resolved remote host */
int http_ver; /* Request HTTP version. 0 = HTTP/0.9, 1=HTTP/1.0, 2=HTTP/1.1 */
bool finished; /* Do not accept any more imput from client */
bool send_failed;
bool finished; /* Do not accept any more input from client */
enum parsed_vpath parsed_vpath; /* file area/base access */
int libnum;
file_t file;
......@@ -1492,8 +1493,14 @@ static off_t sock_sendfile(http_session_t *session,char *path, off_t start, off_
char buf[OUTBUF_LEN]; /* Input buffer */
uint64_t remain;
if(startup->options&WEB_OPT_DEBUG_TX)
lprintf(LOG_DEBUG,"%04d %s [%s] Sending %s",session->socket, session->client.protocol, session->host_ip, path);
if(startup->options&WEB_OPT_DEBUG_TX) {
if(start || end)
lprintf(LOG_DEBUG,"%04d %s [%s] Sending bytes %" PRIuOFF "-%" PRIuOFF " of %s"
,session->socket, session->client.protocol, session->host_ip, start, end, path);
else
lprintf(LOG_DEBUG,"%04d %s [%s] Sending %s"
,session->socket, session->client.protocol, session->host_ip, path);
}
if((file=open(path,O_RDONLY|O_BINARY))==-1)
lprintf(LOG_WARNING,"%04d !ERROR %d opening %s",session->socket,errno,path);
else {
......@@ -6225,26 +6232,41 @@ static void respond(http_session_t * session)
if(session->req.send_content && content_length > 0) {
off_t snt=0;
time_t start = time(NULL);
if(session->req.range_start != 0 || (session->req.range_end && session->req.range_end != (content_length - 1)))
lprintf(LOG_INFO,"%04d %s [%s] Sending file: %s (range %"PRIdOFF"-%"PRIdOFF" of %"PRIdOFF" bytes)"
,session->socket, session->client.protocol, session->client.addr, session->req.physical_path
,session->req.range_start,session->req.range_end, content_length);
else
lprintf(LOG_INFO,"%04d %s [%s] Sending file: %s (%"PRIdOFF" bytes)"
,session->socket, session->client.protocol, session->client.addr, session->req.physical_path, content_length);
snt=sock_sendfile(session,session->req.physical_path,session->req.range_start,session->req.range_end);
if(!session->send_failed) {
if(session->req.ld!=NULL) {
if(snt<0)
snt=0;
session->req.ld->size=snt;
}
if(snt>0) {
char cps[32] = "";
time_t e = time(NULL) - start;
if(e < 1)
e = 1;
lprintf(LOG_INFO, "%04d %s [%s] Sent file: %s (%"PRIdOFF" bytes, %ld cps)"
,session->socket, session->client.protocol, session->client.addr, session->req.physical_path, snt, (long)(snt / e));
if(e > 1)
snprintf(cps, sizeof cps, ", %ld cps", (long)(snt / e));
if(snt == content_length)
lprintf(LOG_INFO, "%04d %s [%s] Sent file: %s (%"PRIdOFF" bytes%s)"
,session->socket, session->client.protocol, session->client.addr
,session->req.physical_path, snt, cps);
else
lprintf(LOG_INFO, "%04d %s [%s] Sent %"PRIdOFF" bytes%s (offset %"PRIdOFF"-%"PRIdOFF") of file: %s (%"PRIdOFF" bytes)"
,session->socket, session->client.protocol, session->client.addr
,snt, cps, session->req.range_start, session->req.range_end
,session->req.physical_path, content_length);
if(session->parsed_vpath == PARSED_VPATH_FULL && session->file.name != NULL) {
user_downloaded_file(&scfg, &session->user, &session->client, session->file.dir, session->file.name, snt);
mqtt_file_download(&mqtt, &session->user, session->file.dir, session->file.name, snt, &session->client);
}
}
}
}
session->req.finished=true;
}
......@@ -6428,7 +6450,6 @@ void http_output_thread(void *arg)
char buf[OUTBUF_LEN+12]; /* *MUST* be large enough to hold the buffer,
the size of the buffer in hex, and four extra bytes. */
char *bufdata;
bool failed=false;
int len;
unsigned avail;
int chunked;
......@@ -6547,8 +6568,8 @@ void http_output_thread(void *arg)
len+=2;
}
if(!failed)
sess_sendbuf(session, buf, len, &failed);
if(!session->send_failed)
sess_sendbuf(session, buf, len, &session->send_failed);
pthread_mutex_unlock(&session->outbuf_write);
}
thread_down();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment