[PATCH 0/1] httpd: fix offset for sendfile
Maxim Storchak
m.storchak at gmail.com
Tue Dec 29 15:29:04 UTC 2020
Hello,
Even though httpd has sendfile feature enabled, it has a limited chance to make use of it.
If there is no Range: request header, the offset is wrong:
[pid 32595] read(0, "GET /file.bin HTTP/1.1\r\nUser-Agent: Wget/1.18 (linux-gnu)\r\nAccept: */*\r\nAccept-Encoding: identity\r\nHost: 127.0.0.1:8000\r\nConnection: Keep-Alive\r\n\r\n", 1024) = 147
[pid 32595] write(1, "HTTP/1.1 200 OK\r\nDate: Tue, 29 Dec 2020 14:43:25 GMT\r\nConnection: close\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 8192\r\n\r\n", 188) = 188
[pid 32595] sendfile(1, 3, [18446744073709551615], 9223372036854710272) = -1 EINVAL (Invalid argument)
If Range header is present, the correct offset from the header is used:
[pid 32634] read(0, "GET /file.bin HTTP/1.1\r\nRange: bytes=512-\r\nUser-Agent: Wget/1.18 (linux-gnu)\r\nAccept: */*\r\nAccept-Encoding: identity\r\nHost: 127.0.0.1:8000\r\nConnection: Keep-Alive\r\n\r\n", 1024) = 166
[pid 32634] write(1, "HTTP/1.1 206 Partial Content\r\nDate: Tue, 29 Dec 2020 14:48:49 GMT\r\nConnection: close\r\nContent-type: text/html\r\nContent-Range: bytes 512-8191/8192\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 7680\r\n\r\n", 262) = 262
[pid 32634] sendfile(1, 3, [512] => [8192], 7680) = 7680
... even if the range start is zero:
[pid 32654] read(0, "GET /file.bin HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nRange: bytes=0-\r\n\r\n", 1024) = 103
[pid 32654] write(1, "HTTP/1.1 206 Partial Content\r\nDate: Tue, 29 Dec 2020 14:50:52 GMT\r\nConnection: close\r\nContent-type: text/html\r\nContent-Range: bytes 0-8191/8192\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 8192\r\n\r\n", 260) = 260
[pid 32654] sendfile(1, 3, [0] => [8192], 8192) = 8192
With the patch applied:
[pid 1987] read(0, "GET /file.bin HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\n\r\n", 1024) = 86
[pid 1987] write(1, "HTTP/1.1 200 OK\r\nDate: Tue, 29 Dec 2020 14:56:43 GMT\r\nConnection: close\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 8192\r\n\r\n", 188) = 188
[pid 1987] sendfile(1, 3, [0] => [8192], 9223372036854710272) = 8192
[pid 1987] sendfile(1, 3, [8192], 9223372036854710272) = 0
[pid 2010] read(0, "GET /file.bin HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nRange: bytes=0-\r\n\r\n", 1024) = 103
[pid 2010] write(1, "HTTP/1.1 206 Partial Content\r\nDate: Tue, 29 Dec 2020 15:02:13 GMT\r\nConnection: close\r\nContent-type: text/html\r\nContent-Range: bytes 0-8191/8192\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 8192\r\n\r\n", 260) = 260
[pid 2010] sendfile(1, 3, [0] => [8192], 8192) = 8192
[pid 1985] read(0, "GET /file.bin HTTP/1.1\r\nHost: 127.0.0.1:8000\r\nUser-Agent: curl/7.52.1\r\nAccept: */*\r\nRange: bytes=512-\r\n\r\n", 1024) = 105
[pid 1985] write(1, "HTTP/1.1 206 Partial Content\r\nDate: Tue, 29 Dec 2020 14:56:35 GMT\r\nConnection: close\r\nContent-type: text/html\r\nContent-Range: bytes 512-8191/8192\r\nAccept-Ranges: bytes\r\nLast-Modified: Tue, 29 Dec 2020 14:27:59 GMT\r\nETag: \"5feb3cef-2000\"\r\nContent-Length: 7680\r\n\r\n", 262) = 262
[pid 1985] sendfile(1, 3, [512] => [8192], 7680) = 7680
Maxim Storchak (1):
httpd: fix offset for sendfile
networking/httpd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--
2.28.0
More information about the busybox
mailing list