Skip to content

httplib PUT request fails with Failed to read connection #2458

@Cherrytree56567

Description

@Cherrytree56567

httplib PUT request fails with Failed to read connection
Here is the code I am using

httplib::Client client(authData["vaultURL"]);
httplib::Headers headers = {
    { "authorization", "Bearer " + authData["accessString"].get<std::string>() },
    { "Content-Type", "application/json" },
    { "bitwarden-client-name", "web" },
    { "bitwarden-client-version", "2026.3.0" },
};

nlohmann::json dBody = encryptedData;
dBody["encryptedFor"] = encryptedData["id"];

std::string data = dBody.dump();

auto res = client.Put("/api/ciphers/" + encryptedData["id"].get<std::string>(), headers, data, "application/json");

if (!res) { // fails
    std::string err = httplib::to_string(res.error());
    auto sslerr = res.ssl_error();
    auto sslberr = res.ssl_backend_error();
    if (OnError) {
        OnError("Failed to Update Item");
    }
    logger->error("updateItem request failed");
    return std::unexpected(NetworkState::Failed);
}
if (res->status != 200) {
    if (OnError) {
        OnError("Failed to Update Item");
    }
    logger->error("updateItem failed: {}", res->status);
    return std::unexpected(NetworkState::Failed);
}

auto body = nlohmann::json::parse(res->body);
return body;
}

The correct url, auth token and uri path are being passed.
The server recieves the request but httplib fails with Failed to read connection.
I have tried increasing the buffer size, using SSLClient, setting set_connection_timeout to 30, setting set_keep_alive to true, but none of these work.
I am on the latest httplib.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions