diff --git a/CMakeLists.txt b/CMakeLists.txt index 739da1d..eee1630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,9 @@ if (NOT MSVC) check_symbol_exists(timezone "time.h" HAVE_TIMEZONE) check_symbol_exists(tzset "time.h" HAVE_TZSET) endif() +if (NOT WIN32) + check_symbol_exists(clock_gettime "time.h" HAVE_CLOCK_GETTIME) +endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/utils_config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/utils_config.h") if ("${CMAKE_C_COMPILER_ID}" STREQUAL GNU) diff --git a/http_client.cpp b/http_client.cpp index 0260794..31f081a 100644 --- a/http_client.cpp +++ b/http_client.cpp @@ -1028,3 +1028,18 @@ std::string dumpCookie(std::map cookie) { } return re; } + +std::string Request::toUri() { + std::string re; + if (this->https) { + re += "https://"; + } else { + re += "http://"; + } + re += this->host; + if (this->port != (this->https ? "https" : "http")) { + re += ":" + this->port; + } + re += this->path; + return re; +} diff --git a/http_client.h b/http_client.h index fa2fd66..1685579 100644 --- a/http_client.h +++ b/http_client.h @@ -193,6 +193,7 @@ public: std::string path; std::string method; CookiesBase* cookies = nullptr; + std::string toUri(); private: HttpBody* body = nullptr; }; diff --git a/time_util.cpp b/time_util.cpp index c51bcf7..b6e41bc 100644 --- a/time_util.cpp +++ b/time_util.cpp @@ -63,3 +63,18 @@ time_t time_util::timegm(struct tm* tm) { return now + get_timezone(); #endif } + +time_t time_util::time_ns() { +#if _WIN32 + FILETIME ft; + GetSystemTimeAsFileTime(&ft); + time_t t = ((size_t)ft.dwHighDateTime << 32) | (size_t)ft.dwLowDateTime; + return t; +#elif HAVE_CLOCK_GETTIME + struct timespec ts; + clock_gettime(CLOCK_REALTIME, &ts); + return ts.tv_sec * 1000000000LL + ts.tv_nsec; +#else + return time(NULL) * 1000000000LL; +#endif +} diff --git a/time_util.h b/time_util.h index 7d7b38b..dfc5193 100644 --- a/time_util.h +++ b/time_util.h @@ -17,5 +17,6 @@ namespace time_util { char* strptime(const char* s, const char* format, struct tm* tm); long get_timezone(); time_t timegm(struct tm* tm); + time_t time_ns(); } #endif diff --git a/utils_config.h.in b/utils_config.h.in index fe92201..a29b5b9 100644 --- a/utils_config.h.in +++ b/utils_config.h.in @@ -26,3 +26,4 @@ #cmakedefine HAVE_TIMEZONE @HAVE_TIMEZONE@ #cmakedefine HAVE_TZSET @HAVE_TZSET@ #cmakedefine HAVE_FPRINTF_S @HAVE_FPRINTF_S@ +#cmakedefine HAVE_CLOCK_GETTIME @HAVE_CLOCK_GETTIME@