A high-performance HTTP web server for binary caching with vcpkg, built with C++ and Drogon framework.
This project is licensed under the GNU General Public License v3.0.
- RESTful API for binary package management
- Fast HTTP server powered by Drogon
- Efficient storage with subdirectory organization
- Package validation with hash checking
- Statistics tracking for uploads/downloads
- Configurable via command-line or environment variables
- Production-ready with error handling and logging
- C++20 compatible compiler (GCC 8+, Clang 7+, MSVC 2022+)
- CMake 3.15 or higher
- vcpkg package manager
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh # Linux/macOS
# or
.\bootstrap-vcpkg.bat # WindowsThis assumes usage of vcpkg in manifest mode
# Clone the repository
git clone https://github.com/viperman1271/vcpkg-http-cache
cd vcpkg-binary-cache-server
# Configure with vcpkg toolchain
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%/scripts/buildsystems/vcpkg.cmake -S . -B build -G "Visual Studio 17 2022" # Windows
# or
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake -S . -B build # Linux/macOS
# Build
cmake --build build --config Debug -j4./bin/vcpkg-binary-cache-server # Linux
# -OR-
.\bin\Release\vcpkg-binary-cache-server.exe # WindowsThis starts the server on 0.0.0.0:80 with cache directory /var/vcpkg.cache/cache (Linux) or C:\.vcpkg.cache\cache (Windows).
./vcpkg-binary-cache-server
OPTIONS:
-h, --help Print this help message and exit
-c, --config TEXT The config file to load (default: /etc/vcpkg.cache/config.toml)
-s, --save Force save the configuration file (if it exists or not). Default:
false
-d, --daemon Forces the application to run as a daemon. Default: false # Linux onlyIf the options have specified the need for an API Key for read, upload, or status endpoints, the vcpkg (or CURL) must include the API Key as a header.
curl -H "Authorization: Bearer vcpkg_28ea09345eef27c3c93759e530516427" http://localhost/statusHEAD /{triplet}/{name}/{version}/{sha}Returns 200 OK if package exists, 404 Not Found if it doesn't.
Example:
curl -I http://localhost/x64-windows/curl/8.17.0/66672cc2e2ace73f33808e213287489112b3a9f1667f0f78b8af05003ebc262fGET /{triplet}/{name}/{version}/{sha}Downloads the binary package with the specified hash.
Example:
curl -O http://localhost/x64-windows/curl/8.17.0/66672cc2e2ace73f33808e213287489112b3a9f1667f0f78b8af05003ebc262fPUT /{triplet}/{name}/{version}/{sha}Uploads a binary package with the specified hash.
Example:
curl -X PUT --data-binary @package.zip http://localhost/x64-windows/curl/8.17.0/66672cc2e2ace73f33808e213287489112b3a9f1667f0f78b8af05003ebc262fGET /statusReturns server statistics and cache information.
Example:
curl http://localhost/statusResponse:
{
"service": "vcpkg-binary-cache-server",
"version": "1.0.0",
"cache_directory": "./cache",
"package_count": 42,
"total_size_bytes": 1048576000,
"total_size_mb": 1000.0,
"statistics":
{
"total_requests": 150,
"uploads": 42,
"downloads": 100
}
}POST /api/keysCreate a new API key with the given description and the specified permission
Example:
curl -X POST http://localhost/api/keys -H "Content-Type: application/json" -d "{ \"description\" : \"This is the description of the API key\", \"permission\" : \"readwrite\" }"Response:
{
"apiKey": "vcpkg_28ea09345eef27c3c93759e530516427",
"message": "API key created successfully",
"success": true
}To use this server as a binary cache for vcpkg, configure vcpkg with:
# Set binary cache to use your server
vcpkg install <package> --binarysource="http,http://localhost/{triplet}/{name}/{version}/{sha},readwrite,Authorization: Bearer vcpkg_28ea09345eef27c3c93759e530516427"Or set it in your environment:
export VCPKG_BINARY_SOURCES="http,http://localhost/{triplet}/{name}/{version}/{sha},readwrite,Authorization: Bearer vcpkg_28ea09345eef27c3c93759e530516427" # LinuxThe key vcpkg_28ea09345eef27c3c93759e530516427 is used as an example, and should not be considered a valid value. It should be replaced with the API key that was generated.
- Thread Pool: Adjust threads based on your CPU cores
- File System: Use a fast filesystem (SSD recommended) for cache directory
- Network: Configure appropriate firewall rules for production deployment
- Memory: Drogon uses asynchronous I/O, keeping memory usage low
Important Security Considerations:
- This server does NOT include authentication
- By default, authentication is not required. Configure limitations in the options (status, read, write)
- For production use, add authentication middleware or configure internal authentication
- Consider using HTTPS with a reverse proxy (nginx, Apache, Caddy)
- Validate uploaded package integrity
- Implement rate limiting for uploads
Contributions are welcome! Please ensure:
- Code follows C++20 standards
- All endpoints are tested
- Documentation is updated
- CLI11: Command line interface
- Drogon: High-performance HTTP framework
- nlohmann::json: JSON parsing and generation
- toml11: TOML parsing and generation
These are automatically managed by vcpkg through the vcpkg.json manifest file.