Skip to content

HTTP Proxy Support #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed

HTTP Proxy Support #68

wants to merge 6 commits into from

Conversation

embeddedmz
Copy link
Contributor

I added and tested a method to set a web HTTP proxy address and to tunnel an operation through it.
If the provided proxy address is invalid, the operation will fail and it's confirmed with the unit test "TestInvalidProxy".

The test I wrote (TestProxy) is based on a hard-coded proxy address from https://www.sslproxies.org/

Personally, in my Google Test unit tests, I parse a configuration file (via simpleini API) to fetch test environment parameters (proxy/URL addresses, local paths...), this technique can be used to update the proxy address used in the unit test if it's not valid anymore and it will offer versatility for the other parameters used in the other unit tests.

@mrtazz mrtazz added this to the v0.5.0 milestone Dec 17, 2016
@mrtazz
Copy link
Owner

mrtazz commented Dec 17, 2016

This looks great! Thank you for taking the time to send this pull request! Could you document the usage of this new feature in the README and also add doxygen headers to the newly added method?

if (uriProxyUpper.compare(0, 4, "HTTP") != 0)
this->uriProxy = "http://" + uriProxy;
else
this->uriProxy = uriProxy;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line seems to not be covered by a unit test (see here). Do you know of an https proxy you could use to test this behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add a test similar to "TestProxy" and provide a proxy address that begins with "http" or "https". I think that the proxy I already used in that test is a one using SSL but I might be wrong.

Copy link
Contributor Author

@embeddedmz embeddedmz Dec 17, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most important thing is to mention the port of the proxy at the end of the address, the prefix of the address whether it's http:// or https:// doesn't matter. An HTTPS proxy is considered a HTTP proxy. More info here : https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html , here https://curl.haxx.se/libcurl/c/CURLOPT_HTTPPROXYTUNNEL.html and here https://curl.haxx.se/libcurl/c/CURLOPT_PROXYTYPE.html

std::transform(uriProxyUpper.begin(), uriProxyUpper.end(),
uriProxyUpper.begin(), ::toupper);

if (uriProxyUpper.compare(0, 4, "HTTP") != 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add curly braces to match the overall style of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I ll do it !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@@ -209,6 +211,21 @@ RestClient::Connection::SetKeyPath(const std::string& keyPath) {
this->keyPath = keyPath;
}

void
RestClient::Connection::SetProxy(const std::string& uriProxy) {
if (uriProxy.empty())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add curly braces to match the overall style of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done !

@mrtazz mrtazz closed this in 83dc690 Dec 24, 2016
@mrtazz
Copy link
Owner

mrtazz commented Dec 24, 2016

merged! Thanks again for taking the time to contribute!

embeddedmz added a commit to embeddedmz/restclient-cpp that referenced this pull request Dec 28, 2016
Fixed code indentation to comply with Cpplint.

Added web proxy tunneling support.

this adds support for using proxies corresponding to the CURLOPT_PROXY
and CURLOPT_HTTPPROXYTUNNEL config options in libcurl.

closes mrtazz#68

default to 10s timeout in unit tests

this makes the conn object in unit tests default to a 10s timeout in
order to fail fast if something is up with the connection or configured
hosts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants