Skip to content

Commit e6bcb8f

Browse files
committed
make first-load/not case explicit
1 parent 2b3094c commit e6bcb8f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

logtail.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ function get_log() {
2424
loading = true;
2525

2626
var range;
27-
if (log_size === 0)
27+
var first_load;
28+
if (log_size === 0) {
2829
/* Get the last 'load' bytes */
2930
range = "-" + load.toString();
30-
else
31+
first_load = true;
32+
} else {
3133
/* Get the (log_size - 1)th byte, onwards. */
3234
range = (log_size - 1).toString() + "-";
35+
first_load = false;
36+
}
3337

3438
/* The "log_size - 1" deliberately reloads the last byte, which we already
3539
* have. This is to prevent a 416 "Range unsatisfiable" error: a response
@@ -60,7 +64,7 @@ function get_log() {
6064
if (isNaN(size))
6165
throw "Invalid Content-Range size";
6266
} else if (xhr.status === 200) {
63-
if (log_size > 1)
67+
if (!first_load)
6468
throw "Expected 206 Partial Content";
6569

6670
size = xhr.getResponseHeader("Content-Length");
@@ -69,7 +73,7 @@ function get_log() {
6973

7074
var added = false;
7175

72-
if (log_size === 0) {
76+
if (first_load) {
7377
/* Clip leading part-line if not the whole file */
7478
if (content_size < size) {
7579
var start = data.indexOf("\n");

0 commit comments

Comments
 (0)