From 27103692040ec0ae1bfdad9c6804ef68cf2323a1 Mon Sep 17 00:00:00 2001 From: Coldwings Date: Fri, 17 Nov 2023 14:06:27 +0800 Subject: [PATCH] Fix httpfs may return wrong received body length if http socket disconnected during body transfering Signed-off-by: Coldwings --- fs/httpfs/httpfs.cpp | 3 +-- net/curl.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/httpfs/httpfs.cpp b/fs/httpfs/httpfs.cpp index 5a6ff0d7..4ef3e207 100644 --- a/fs/httpfs/httpfs.cpp +++ b/fs/httpfs/httpfs.cpp @@ -229,8 +229,7 @@ class HttpFile : public fs::VirtualReadOnlyFile { VALUE(url), VALUE(offset), VALUE(ret)); } authorized = true; - headers.try_get("content-length", ret); - return ret; + return writer.written; } int fstat(struct stat* buf) override { diff --git a/net/curl.h b/net/curl.h index 65dee2f2..37fee819 100644 --- a/net/curl.h +++ b/net/curl.h @@ -145,9 +145,11 @@ class StringWriter { struct IOVWriter : public IOVector { using IOVector::IOVector; size_t drop = 0; + size_t written = 0; size_t write(const void* buf, size_t size) { auto actual_count = memcpy_from( buf, size); // copy from (buf, size) to iovec[] in *this, + written += actual_count; extract_front(actual_count); // and extract the portion just copied if (actual_count < size) // means full {