Skip to content

Commit

Permalink
Fix httpfs may return wrong received body length if http socket disco…
Browse files Browse the repository at this point in the history
…nnected during body transfering

Signed-off-by: Coldwings <[email protected]>
  • Loading branch information
Coldwings committed Nov 17, 2023
1 parent 5dc961e commit d4b4b86
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions fs/httpfs/httpfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions net/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit d4b4b86

Please sign in to comment.