Skip to content

Commit ba91bff

Browse files
committed
Make SetProxy behave like curl's CURLOPT_PROXY
this changes the behaviour of SetProxy from just returning on an empty string to assigning it. This emulates the curl behaviour of disabling the proxy on an empty string. fixes mrtazz#73
1 parent 8d6b7d5 commit ba91bff

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

source/connection.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,13 @@ RestClient::Connection::SetKeyPassword(const std::string& keyPassword) {
249249
*/
250250
void
251251
RestClient::Connection::SetProxy(const std::string& uriProxy) {
252-
if (uriProxy.empty()) {
253-
return;
254-
}
255252

256253
std::string uriProxyUpper = uriProxy;
257254
// check if the provided address is prefixed with "http"
258255
std::transform(uriProxyUpper.begin(), uriProxyUpper.end(),
259256
uriProxyUpper.begin(), ::toupper);
260257

261-
if (uriProxyUpper.compare(0, 4, "HTTP") != 0) {
258+
if ((uriProxy.length() > 0) && (uriProxyUpper.compare(0, 4, "HTTP") != 0)) {
262259
this->uriProxy = "http://" + uriProxy;
263260
} else {
264261
this->uriProxy = uriProxy;

test/test_connection.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ TEST_F(ConnectionTest, TestProxy)
224224
EXPECT_EQ(200, res.code);
225225
}
226226

227+
TEST_F(ConnectionTest, TestUnSetProxy)
228+
{
229+
conn->SetProxy("127.0.0.1:3128");
230+
conn->SetProxy("");
231+
RestClient::Response res = conn->get("/get");
232+
EXPECT_EQ(200, res.code);
233+
}
234+
227235
TEST_F(ConnectionTest, TestProxyAddressPrefixed)
228236
{
229237
conn->SetProxy("http://127.0.0.1:3128");

0 commit comments

Comments
 (0)