Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: libcpr/cpr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: eebff4452efb4790b8c0c052d649ffbe2257b3a2
Choose a base ref
..
head repository: libcpr/cpr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 59ddfd0ca9df3794be4c439d2cc77ead0b85c8a4
Choose a head ref
27 changes: 22 additions & 5 deletions .github/workflows/build-deb.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
name: Build Debian Package
on:
push:
tags:
- 1.**
pull_request:
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]
workflow_dispatch:
inputs:
version:
description: 'The optional semantic version number. If not supplied the branch/tag will be used.'
type: string

jobs:
package-ubuntu-latest-amd64:
@@ -22,11 +25,25 @@ jobs:
run: sudo apt install -y libssl-dev libcurl4-openssl-dev
- name: "Install building tools"
run: sudo apt install -y cmake debmake devscripts debhelper

# Set version number
- name: Set version based on input
if: ${{ inputs.version }}
run: echo "RELEASE_VERSION=${{ inputs.version }}" >> "$GITHUB_ENV"
- name: Set version based on ref
if: ${{ !inputs.version }}
run: |
mkdir -p cpr/build
pushd cpr/build
cmake .. -DCPR_BUILD_VERSION_OUTPUT_ONLY=ON
echo "RELEASE_VERSION=$(cat version.txt)" >> $GITHUB_ENV
popd
rm -rf cpr/build
- name: Print Version
run: echo "deb version will be '${{ env.RELEASE_VERSION }}'"
# Build package of runtime library
- name: "Package build of runtime library"
env:
VERSION: ${{ github.ref_name }}
VERSION: ${{ env.RELEASE_VERSION }}
run: bash cpr/package-build/build-package.sh cpr

- name: "Upload deb-packages"
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ jobs:
ubuntu-clang-openssl:
strategy:
matrix:
container: ["ubuntu:18.04", "ubuntu:20.04", "ubuntu:22.04", "ubuntu:23.04"]
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:23.04", "ubuntu:24.04"]
systemCurl: [ON, OFF]
buildType: [Debug, Release]
runs-on: ubuntu-latest
@@ -49,7 +49,7 @@ jobs:
ubuntu-gcc-openssl:
strategy:
matrix:
container: ["ubuntu:18.04", "ubuntu:20.04", "ubuntu:22.04", "ubuntu:23.04"]
container: ["ubuntu:20.04", "ubuntu:22.04", "ubuntu:23.04", "ubuntu:24.04"]
systemCurl: [ON, OFF]
buildType: [Debug, Release]
runs-on: ubuntu-latest
9 changes: 2 additions & 7 deletions .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
@@ -9,14 +9,9 @@ jobs:
steps:
- name: Update package list
run: sudo dnf update -y
- name: Install dependencies
run: sudo dnf install -y openssl-devel cmake git gcc clang ninja-build
- name: Install clang-tidy
- name: Install clang-format
run: sudo dnf install -y clang-tools-extra
- name: Checkout
uses: actions/checkout@v3
- name: Check format
uses: RafikFarhad/clang-format-github-action@3.2.0
with:
sources: "include/**/*.hpp,include/**/*.cpp,cpr/**/*.hpp,cpr/**/*.cpp"
style: "file"
run: bash scripts/check_clang_format.sh
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -47,8 +47,10 @@ _site/
*.swp

# VSCode
.vscode/
.vscode/*
!.vscode/tasks.json
.vs/
!.vs/tasks.json

# clangd
.cache/
62 changes: 62 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "🗑️ Delete build dir",
"type": "shell",
"command": "${workspaceFolder}/scripts/delete_build_dir.sh",
"problemMatcher": [],
"group": {
"kind": "build"
},
"presentation": {
"clear": true
},
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "📝 Run clang-format",
"type": "shell",
"command": "${workspaceFolder}/scripts/run_clang_format.sh",
"args": [
"cpr",
"include",
"test"
],
"problemMatcher": [],
"group": {
"kind": "build"
},
"presentation": {
"clear": true
},
"options": {
"cwd": "${workspaceFolder}"
}
},
{
"label": "📑 Check clang-format",
"type": "shell",
"command": "${workspaceFolder}/scripts/check_clang_format.sh",
"args": [
"cpr",
"include",
"test"
],
"problemMatcher": [],
"group": {
"kind": "build"
},
"presentation": {
"clear": true
},
"options": {
"cwd": "${workspaceFolder}"
}
}
]
}
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -48,7 +48,6 @@ macro(cpr_option OPTION_NAME OPTION_TEXT OPTION_DEFAULT)
message(STATUS " ${OPTION_NAME}: ${${OPTION_NAME}}")
endmacro()

option(BUILD_SHARED_LIBS "Build libraries as shared libraries" ON)
message(STATUS "C++ Requests CMake Options")
message(STATUS "=======================================================")
cpr_option(CPR_GENERATE_COVERAGE "Set to ON to generate coverage reports." OFF)
@@ -67,6 +66,7 @@ cpr_option(CPR_ENABLE_CPPCHECK "Set to ON to enable Cppcheck static analysis. Re
cpr_option(CPR_BUILD_TESTS "Set to ON to build cpr tests." OFF)
cpr_option(CPR_BUILD_TESTS_SSL "Set to ON to build cpr ssl tests" ${CPR_BUILD_TESTS})
cpr_option(CPR_BUILD_TESTS_PROXY "Set to ON to build proxy tests. They fail in case there is no valid proxy server available in proxy_tests.cpp" OFF)
cpr_option(CPR_BUILD_VERSION_OUTPUT_ONLY "Set to ON to only export the version into 'build/version.txt' and exit" OFF)
cpr_option(CPR_SKIP_CA_BUNDLE_SEARCH "Skip searching for Certificate Authority certs. Turn ON for systems like iOS where file access is restricted and prevents https from working." OFF)
cpr_option(CPR_USE_BOOST_FILESYSTEM "Set to ON to use the Boost.Filesystem library. This is useful, on, e.g., Apple platforms, where std::filesystem may not always be available when targeting older OS versions." OFF)
cpr_option(CPR_DEBUG_SANITIZER_FLAG_THREAD "Enables the ThreadSanitizer for debug builds." OFF)
@@ -76,6 +76,13 @@ cpr_option(CPR_DEBUG_SANITIZER_FLAG_UB "Enables the UndefinedBehaviorSanitizer f
cpr_option(CPR_DEBUG_SANITIZER_FLAG_ALL "Enables all sanitizers for debug builds except the ThreadSanitizer since it is incompatible with the other sanitizers." OFF)
message(STATUS "=======================================================")

# Save the project version as txt file for deb and NuGet builds
if(CPR_BUILD_VERSION_OUTPUT_ONLY)
message(STATUS "Printing version and exiting...")
file(WRITE "${CMAKE_BINARY_DIR}/version.txt" "${PROJECT_VERSION}")
return()
endif()

if (CPR_FORCE_USE_SYSTEM_CURL)
message(WARNING "The variable CPR_FORCE_USE_SYSTEM_CURL is deprecated, please use CPR_USE_SYSTEM_CURL instead")
set(CPR_USE_SYSTEM_CURL ${CPR_FORCE_USE_SYSTEM_CURL})
@@ -279,8 +286,8 @@ else()
cmake_policy(SET CMP0135 NEW)
endif()
FetchContent_Declare(curl
URL https://github.com/curl/curl/releases/download/curl-8_7_1/curl-8.7.1.tar.xz
URL_HASH SHA256=6fea2aac6a4610fbd0400afb0bcddbe7258a64c63f1f68e5855ebc0c659710cd # the file hash for curl-8.7.1.tar.xz
URL https://github.com/curl/curl/releases/download/curl-8_10_1/curl-8.10.1.tar.xz
URL_HASH SHA256=73a4b0e99596a09fa5924a4fb7e4b995a85fda0d18a2c02ab9cf134bebce04ee # the file hash for curl-8.10.1.tar.xz
USES_TERMINAL_DOWNLOAD TRUE) # <---- This is needed only for Ninja to show download progress
FetchContent_MakeAvailable(curl)

14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -118,6 +118,16 @@ cmake .. -DCPR_USE_SYSTEM_CURL=ON
cmake --build . --parallel
sudo cmake --install .
```
#### Build Static Library
As an alternative if you want to switch between a static or shared version of cpr use ['-DBUILD_SHARED_LIBS=ON/OFF'](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html).
```Bash
git clone https://github.com/libcpr/cpr.git
cd cpr && mkdir build && cd build
cmake .. -DCPR_USE_SYSTEM_CURL=ON -DBUILD_SHARED_LIBS=OFF
cmake --build . --parallel
sudo cmake --install .
```

In your `CMakeLists.txt`:
```cmake
find_package(cpr REQUIRED)
@@ -156,6 +166,10 @@ For Windows, there is also a libcpr NuGet package available. Currently, x86 and

The package can be found here: [NuGet.org](https://www.nuget.org/packages/libcpr/)

### Port for macOS

On macOS you may install cpr via [MacPorts.org](https://ports.macports.org/port/cpr) (arm64, x86_64, powerpc)

## Requirements

The only explicit requirements are:
10 changes: 10 additions & 0 deletions cpr/auth.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
#include "cpr/auth.h"
#include "cpr/util.h"

#include <string_view>

namespace cpr {

Authentication::Authentication(std::string_view username, std::string_view password, AuthMode auth_mode) : auth_mode_{auth_mode} {
auth_string_.reserve(username.size() + 1 + password.size());
auth_string_ += username;
auth_string_ += ':';
auth_string_ += password;
}

Authentication::~Authentication() noexcept {
util::secureStringClear(auth_string_);
}
Loading