Skip to content

Commit 61545c9

Browse files
committed
Add configurable OpenSSL build modes and fail fast on HTTPS-only builds.
1 parent df6889b commit 61545c9

3 files changed

Lines changed: 44 additions & 7 deletions

File tree

Makefile

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,29 @@
55
CXX = g++
66
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -I./include -I./vendor/json
77
LDFLAGS =
8+
OPENSSL ?= auto
89

910
# Build directory
1011
BUILD_DIR = build
1112
OBJ_DIR = $(BUILD_DIR)/obj
1213
BIN_DIR ?= .
1314

14-
# Check for OpenSSL
15-
ifneq ($(shell pkg-config --exists openssl && echo yes),)
16-
CXXFLAGS += -DHLQUERY_HAS_OPENSSL
15+
# Optional OpenSSL support
16+
ifeq ($(OPENSSL),1)
17+
ifneq ($(shell pkg-config --exists openssl && echo yes),yes)
18+
$(error OpenSSL was requested with OPENSSL=1, but pkg-config could not find openssl)
19+
endif
20+
CXXFLAGS += $(shell pkg-config --cflags openssl) -DHLQUERY_HAS_OPENSSL
1721
LDFLAGS += $(shell pkg-config --libs openssl)
22+
else ifeq ($(OPENSSL),auto)
23+
ifeq ($(shell pkg-config --exists openssl && echo yes),yes)
24+
CXXFLAGS += $(shell pkg-config --cflags openssl) -DHLQUERY_HAS_OPENSSL
25+
LDFLAGS += $(shell pkg-config --libs openssl)
26+
endif
27+
else ifeq ($(OPENSSL),0)
28+
# Build HTTP-only client without OpenSSL.
29+
else
30+
$(error Unsupported OPENSSL value '$(OPENSSL)'; use OPENSSL=auto, OPENSSL=1, or OPENSSL=0)
1831
endif
1932

2033
# Source files

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<div align="center">
66

7-
**A high-performance search engine built for modern applications**
7+
**A C++ API for a high-performance search engine built for modern applications**
88

99
[![Twitter Follow](https://img.shields.io/twitter/url/https/x.com/hlquery.svg?style=social&label=Follow%20%40hlquery)](https://x.com/hlquery)
1010
[![Linux Build](https://github.com/hlquery/cpp-api/workflows/Linux%20build/badge.svg)](https://github.com/hlquery/cpp-api/actions)
@@ -47,6 +47,19 @@ cd etc/api/cpp
4747
make
4848
```
4949

50+
Build modes:
51+
52+
```bash
53+
# Auto-detect OpenSSL with pkg-config (default)
54+
make
55+
56+
# Force HTTP-only build with no OpenSSL dependency
57+
make OPENSSL=0
58+
59+
# Require OpenSSL and fail fast if it is not available
60+
make OPENSSL=1
61+
```
62+
5063
## Building
5164

5265
### Using Make
@@ -69,6 +82,10 @@ make clean
6982

7083
This removes the entire `build/` directory.
7184

85+
On systems where OpenSSL is installed outside the default compiler include path
86+
(for example Homebrew on macOS), the Makefile now pulls both compiler and linker
87+
flags from `pkg-config`.
88+
7289
## Quick Start
7390

7491
```cpp
@@ -194,6 +211,9 @@ options["tls_verify"] = "false"; // intentionally unsafe
194211
hlquery::Client client("https://localhost:9200", options);
195212
```
196213

214+
If the client is built with `OPENSSL=0`, only `http://` endpoints are supported.
215+
Using an `https://` URL in that mode raises a `RequestException`.
216+
197217
### Authentication
198218

199219
```cpp

src/request.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ Response Request::makeHttpRequest(const std::string& method, const std::string&
118118
bool use_ssl;
119119
parseUrl(url, host, port, use_ssl);
120120

121+
#if !defined(HLQUERY_HAS_OPENSSL)
122+
if (use_ssl)
123+
{
124+
throw RequestException("HTTPS requested, but this build of the hlquery C++ client was compiled without OpenSSL support");
125+
}
126+
#endif
127+
121128
std::string path = url;
122129
if (url.find("://") != std::string::npos)
123130
{
@@ -276,9 +283,6 @@ Response Request::makeHttpRequest(const std::string& method, const std::string&
276283
{
277284
#ifdef HLQUERY_HAS_OPENSSL
278285
sent = SSL_write(ssl, request_str.c_str(), request_str.length());
279-
#else
280-
close(sock);
281-
throw RequestException("SSL not available but HTTPS URL requested");
282286
#endif
283287
}
284288
else

0 commit comments

Comments
 (0)