Skip to content
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

Initial classes to make http requests. #507

Merged
merged 10 commits into from May 15, 2018

Conversation

coryan
Copy link
Member

@coryan coryan commented May 10, 2018

This includes an integration test to make a remote http request.

@coryan coryan added the api: storage Issues related to the Cloud Storage API. label May 10, 2018
@coryan coryan requested a review from houglum May 10, 2018 21:02
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label May 10, 2018
@houglum
Copy link
Contributor

houglum commented May 14, 2018

Saw some revisions to this over the weekend, and Travis looks like it's failing as-is. I've already looked over most of this, but please @-mention me when this PR is passing and you want my final review :)

@coryan
Copy link
Member Author

coryan commented May 14, 2018

@houglum PTAL. Tests pass now.

@@ -56,16 +56,22 @@ google_cloud_cpp_add_common_options(storage_common_options)
# Enable unit tests
enable_testing()

# Search for libcurl
# Search for libcurl, in CMake 3.5 this does not define a target, but it does in later versions.
# Define the target ourselves if it is missing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Still getting acquainted with CMake... maybe I missed it, but I don't see anything different in the CMake docs for find_package between v3.4 and v3.6. Also, the comment below says that the find_package calls do define a target in CMake 3.5. I'm just confused as to which versions do what, and why. Are there docs or some explanation of this you can link?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just added a link, it is in development (use the git-stage pull down in the documentation). Generally, we are sticking to cmake-3.5 because it is easier for our users to find that one in the
platforms we support.

find_package(CURL REQUIRED)
if (NOT TARGET CURL::CURL)
add_library(CURL::CURL UNKNOWN IMPORTED)
set_target_properties(CURL::CURL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIR}")
set_property(TARGET CURL::CURL APPEND PROPERTY IMPORTED_LOCATION "${CURL_LIBRARY}")
endif ()

# Find OpenSSL and ZLIB, these define targets as-of CMake 3.5 and higher.
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is only required for Windows -- could you add a comment to that effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think (but I might be wrong), that these are actually required when linking statically, it just happens that Windows in the only platform where we are forcing static linking of system-provided libraries. I added a comment saying that.

As to why Windows is linked statically: because grpc does not support shared libraries on Windows. And as to why not link statically in one of the Linux builds, that is a bug, created #510 to track it.

@coryan
Copy link
Member Author

coryan commented May 15, 2018

@houglum PTAL.

*/
std::string CurlRequest::MakeRequest(std::string const& payload) {
// Pre-compute and cache the user agent string:
static std::string const user_agent = [] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably not super important for the initial version of this class, but users often want to use a custom user agent (IIRC, we tack their custom string on the end of our standardized user agent... but I'd have to check with the client libraries folks). Might be useful to allow setting a custom user agent segment elsewhere and include it in this string - we can make a TODO for that and shelve it for now though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ack, created #511 to track this, and added a placeholder into the design document.

connected=no
readonly ATTEMPTS=$(seq 1 8)
for attempt in $ATTEMPTS; do
if curl "https://nghttp2.org/httpbin/get" >/dev/null 2>&1; then
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for picking this particular URL?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you can get the contents of your request in the response, and simulate failures, and return blobs of data too:

https://nghttp2.org/httpbin/

Makes it convenient for small tests like this, but we should be nice and not abuse their site.

@coryan coryan merged commit 45683c6 into googleapis:master May 15, 2018
@coryan coryan deleted the add-curl-requests branch May 15, 2018 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants