Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ build/
.xmake/
# mcpp build artefacts
target/
compile_commands.json
5 changes: 0 additions & 5 deletions .xlings.json

This file was deleted.

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Minimal C++23 HTTP/HTTPS client library with SSE (Server-Sent Events) streaming
- HTTP/HTTPS client with connection pooling (keep-alive)
- SSE (Server-Sent Events) streaming
- Proxy support (HTTP CONNECT)
- Segmented parallel downloads via HTTP Range (aria2-style)
- C++23 modules

## Usage
Expand All @@ -28,6 +29,41 @@ auto resp = client.send(mcpplibs::tinyhttps::HttpRequest::post(
));
```

## Parallel downloads

`download_to_file_parallel()` probes the server with `Range: bytes=0-0`; when
the server answers 206 the file is split into segments fetched concurrently
into a pre-allocated file. It falls back to a plain sequential download when
the server ignores Range (200) or the file is too small to split.

```cpp
import mcpplibs.tinyhttps;
namespace https = mcpplibs::tinyhttps;

https::HttpClientConfig cfg;
cfg.maxConnectionsPerFile = 8; // concurrent segment workers
cfg.maxSegments = 16; // aria2 -s: split count (0 = tie to connections)
cfg.minSegmentBytes = 4 << 20; // aria2 --min-split-size: 4 MiB

https::HttpClient client(cfg);
auto result = client.download_to_file_parallel(
"https://example.com/big.iso",
"big.iso",
[](std::int64_t total, std::int64_t done) {
// monotonic progress; total is 0 when unknown
},
[] { return false; } // return true to cancel
);
if (result.ok()) { /* result.bytesWritten, result.expectedBytes, ... */ }
```

Behavior notes:

- Segment boundaries never overlap; interrupted segments resume mid-range on
retry (up to 2 retries per segment).
- Progress callbacks are serialized and monotonically increasing.
- The pre-allocated target file is removed if the download fails.

## 使用 mcpp 构建

### 添加依赖
Expand Down
2 changes: 1 addition & 1 deletion mcpp.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ version = 2
namespace = "compat"
version = "3.6.1"
source = "index+compat@3.6.1"
hash = "fnv1a:83dea67ac1379be3"
hash = "fnv1a:bb700e69e973ccd0"

8 changes: 6 additions & 2 deletions mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Local fork of mcpplibs/tinyhttps 0.2.9 with segmented parallel downloads
# (HTTP Range multi-connection, aria2-style). All existing API is unchanged;
# the new surface is HttpClientConfig.maxConnectionsPerFile and
# HttpClient::download_to_file_parallel().
[package]
namespace = "mcpplibs"
name = "tinyhttps"
version = "0.2.9"
description = "Minimal C++23 HTTP/HTTPS client with SSE streaming support"
version = "0.3.0"
description = "Minimal C++23 HTTP/HTTPS client (fork: + Range segmented parallel download)"
license = "Apache-2.0"
repo = "https://github.com/mcpplibs/tinyhttps"

Expand Down
Loading