Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 392eaa4678 | |||
| 4ea29e5789 | |||
| b4723459b2 | |||
| 3f9171737c | |||
| fb14afe8d9 |
@ -1,10 +1,12 @@
|
|||||||
project(librcw)
|
project(librcw)
|
||||||
cmake_minimum_required(VERSION 3.0.2)
|
cmake_minimum_required(VERSION 3.0.2)
|
||||||
include(GNUInstallDirs)
|
|
||||||
|
|
||||||
set(librcw_VERSION_STRING "000001000L")
|
include(GNUInstallDirs)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
|
||||||
|
set(librcw_VERSION_STRING "000003000L")
|
||||||
set(librcw_VERSION_MAJOR 0)
|
set(librcw_VERSION_MAJOR 0)
|
||||||
set(librcw_VERSION_MINOR 1)
|
set(librcw_VERSION_MINOR 3)
|
||||||
set(librcw_VERSION_REVISION 0)
|
set(librcw_VERSION_REVISION 0)
|
||||||
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
set(INCLUDE_PATH ${CMAKE_SOURCE_DIR}/include)
|
||||||
include_directories(BEFORE SYSTEM "${INCLUDE_PATH}")
|
include_directories(BEFORE SYSTEM "${INCLUDE_PATH}")
|
||||||
@ -15,17 +17,23 @@ option(ENABLE_PROFILING "Enable asan" OFF)
|
|||||||
option(BUILD_TESTS "Enable testing" OFF)
|
option(BUILD_TESTS "Enable testing" OFF)
|
||||||
mark_as_advanced(ENABLE_PROFILING)
|
mark_as_advanced(ENABLE_PROFILING)
|
||||||
|
|
||||||
|
pkg_check_modules(LIBREXY REQUIRED librexy)
|
||||||
|
|
||||||
|
set(LIBREXY_REAL_LIBRARIES ${LIBREXY_LIBRARIES})
|
||||||
|
list(TRANSFORM LIBREXY_REAL_LIBRARIES PREPEND "-l")
|
||||||
|
|
||||||
set(SOURCE_LIST "src/async.cpp" "src/curl_easy_handle.cpp" "src/curl_header_list.cpp" "src/httpint.cpp" "src/read_write_cback.cpp" "src/response.cpp" "src/sync.cpp" "src/types.cpp")
|
set(SOURCE_LIST "src/async.cpp" "src/curl_easy_handle.cpp" "src/curl_header_list.cpp" "src/httpint.cpp" "src/read_write_cback.cpp" "src/response.cpp" "src/sync.cpp" "src/types.cpp")
|
||||||
if(ENABLE_SHARED)
|
if(ENABLE_SHARED)
|
||||||
add_library(rcw SHARED ${SOURCE_LIST})
|
add_library(rcw SHARED ${SOURCE_LIST})
|
||||||
set_target_properties(rcw PROPERTIES SOVERSION "${librcw_VERSION_MAJOR}.${librcw_VERSION_MINOR}.${librcw_VERSION_REVISION}")
|
set_target_properties(rcw PROPERTIES SOVERSION "${librcw_VERSION_MAJOR}.${librcw_VERSION_MINOR}")
|
||||||
set(LIBRCW_LIBFLAGS "-lrcw")
|
set(LIBRCW_LIBFLAGS "-lrcw")
|
||||||
target_link_libraries(rcw "-lcurl -lrexy -lpthread")
|
target_link_libraries(rcw "-lcurl -lpthread ${LIBREXY_LINK_LIBRARIES}")
|
||||||
else()
|
else()
|
||||||
add_library(rcw STATIC ${SOURCE_LIST})
|
add_library(rcw STATIC ${SOURCE_LIST})
|
||||||
set(LIBRCW_LIBFLAGS "-lrcw -lcurl -lrexy -lpthread")
|
set(LIBRCW_LIBFLAGS "-lrcw -lcurl -lpthread ${LIBREXY_REAL_LIBRARIES}")
|
||||||
target_link_libraries(rcw "-lcurl -lrexy -lpthread")
|
target_link_libraries(rcw "-lcurl -lpthread ${LIBREXY_LINK_LIBRARIES}")
|
||||||
endif()
|
endif()
|
||||||
|
set_target_properties(rcw PROPERTIES VERSION "${librcw_VERSION_MAJOR}.${librcw_VERSION_MINOR}.${librcw_VERSION_REVISION}")
|
||||||
|
|
||||||
if(ENABLE_PROFILING)
|
if(ENABLE_PROFILING)
|
||||||
target_compile_options(rcw PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
|
target_compile_options(rcw PRIVATE -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls)
|
||||||
@ -37,7 +45,8 @@ if(BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(LIBRCW_PUBLIC_HEADERS "include/async.hpp" "include/curl_easy_handle.hpp" "include/curl_header_list.hpp" "include/httpint.hpp" "include/rcw.hpp" "include/read_write_cback.hpp" "include/response.hpp" "include/string.hpp" "include/sync.hpp" "include/types.hpp")
|
set(LIBRCW_PUBLIC_HEADERS "include/async.hpp" "include/curl_easy_handle.hpp" "include/curl_header_list.hpp" "include/httpint.hpp" "include/rcw.hpp" "include/read_write_cback.hpp" "include/response.hpp" "include/string.hpp" "include/sync.hpp" "include/types.hpp")
|
||||||
target_compile_options(rcw PRIVATE -Wall -Wextra -pedantic -std=c++17)
|
target_compile_options(rcw PRIVATE -Wall -Wextra -pedantic -std=c++17 ${LIBREXY_CFLAGS_OTHER})
|
||||||
|
target_include_directories(rcw PUBLIC ${LIBREXY_INCLUDE_DIRS})
|
||||||
|
|
||||||
install(TARGETS rcw
|
install(TARGETS rcw
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
|||||||
@ -78,19 +78,19 @@ namespace rcw{
|
|||||||
void reset(void);
|
void reset(void);
|
||||||
response perform(void);
|
response perform(void);
|
||||||
|
|
||||||
string escape_to_str(const char* data, int len = 0);
|
string escape(const char* data, int len = 0);
|
||||||
string escape_to_str(const rexy::string_base<char>& data);
|
string escape(rexy::string_view data);
|
||||||
std::string escape_to_std(const char* data, int len = 0);
|
std::string escape_to_std(const char* data, int len = 0);
|
||||||
std::string escape_to_std(const rexy::string_base<char>& data);
|
std::string escape_to_std(rexy::string_view data);
|
||||||
char* escape_to_cstr(const char* data, int* outlen, int len = 0);
|
char* escape_to_cstr(const char* data, int* outlen, int len = 0);
|
||||||
char* escape_to_cstr(const rexy::string_base<char>& data, int* outlen);
|
char* escape_to_cstr(rexy::string_view data, int* outlen);
|
||||||
|
|
||||||
std::string decode_to_std(const char* data, int len = 0);
|
std::string unescape_to_std(const char* data, int len = 0);
|
||||||
std::string decode_to_std(const rexy::string_base<char>& data);
|
std::string unescape_to_std(rexy::string_view data);
|
||||||
string decode_to_str(const char* data, int len = 0);
|
string unescape(const char* data, int len = 0);
|
||||||
string decode_to_str(const rexy::string_base<char>& data);
|
string unescape(rexy::string_view data);
|
||||||
char* decode_to_cstr(const char* data, int* outlen, int len = 0);
|
char* unescape_to_cstr(const char* data, int* outlen, int len = 0);
|
||||||
char* decode_to_cstr(const rexy::string_base<char>& data, int* outlen);
|
char* unescape_to_cstr(rexy::string_view data, int* outlen);
|
||||||
|
|
||||||
long get_last_status(void)const;
|
long get_last_status(void)const;
|
||||||
CURL* get(void);
|
CURL* get(void);
|
||||||
|
|||||||
@ -22,17 +22,17 @@
|
|||||||
namespace rcw{
|
namespace rcw{
|
||||||
|
|
||||||
//class representing http status codes where 200-299 is valid and 300+ is invalid
|
//class representing http status codes where 200-299 is valid and 300+ is invalid
|
||||||
class http_status
|
class httpint
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
long m_code = 200;
|
long m_code = 200;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
http_status(void) = default;
|
httpint(void) = default;
|
||||||
http_status(long x);
|
httpint(long x);
|
||||||
http_status(const http_status&) = default;
|
httpint(const httpint&) = default;
|
||||||
http_status& operator=(const http_status&) = default;
|
httpint& operator=(const httpint&) = default;
|
||||||
http_status& operator=(long x);
|
httpint& operator=(long x);
|
||||||
|
|
||||||
bool ok(void)const;
|
bool ok(void)const;
|
||||||
operator long(void)const;
|
operator long(void)const;
|
||||||
|
|||||||
@ -21,13 +21,13 @@
|
|||||||
|
|
||||||
#define RCW_VERSION @librcw_VERSION_STRING@
|
#define RCW_VERSION @librcw_VERSION_STRING@
|
||||||
|
|
||||||
#include <sync.hpp>
|
#include <rcw/sync.hpp>
|
||||||
#include <async.hpp>
|
#include <rcw/async.hpp>
|
||||||
#include <response.hpp>
|
#include <rcw/response.hpp>
|
||||||
#include <curl_easy_handle.hpp>
|
#include <rcw/curl_easy_handle.hpp>
|
||||||
#include <curl_header_list.hpp>
|
#include <rcw/curl_header_list.hpp>
|
||||||
#include <httpint.hpp>
|
#include <rcw/httpint.hpp>
|
||||||
#include <string.hpp>
|
#include <rcw/string.hpp>
|
||||||
#include <types.hpp>
|
#include <rcw/types.hpp>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -22,16 +22,18 @@
|
|||||||
#include "httpint.hpp"
|
#include "httpint.hpp"
|
||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
|
|
||||||
|
#include <rexy/string_view.hpp>
|
||||||
|
|
||||||
namespace rcw{
|
namespace rcw{
|
||||||
|
|
||||||
class response
|
class response
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
http_status status;
|
httpint status;
|
||||||
size_t elapsed_time_us; //CURLINFO_TOTAL_TIME_T
|
size_t elapsed_time_us; //CURLINFO_TOTAL_TIME_T
|
||||||
size_t uploaded_bytes; //CURLINFO_SIZE_UPLOAD_T
|
size_t uploaded_bytes; //CURLINFO_SIZE_UPLOAD_T
|
||||||
size_t downloaded_bytes; //CURLINFO_SIZE_DOWNLOAD_T
|
size_t downloaded_bytes; //CURLINFO_SIZE_DOWNLOAD_T
|
||||||
rexy::static_string<const char> content_type; //CURLINFO_CONTENT_TYPE
|
rexy::string_view content_type; //CURLINFO_CONTENT_TYPE
|
||||||
int liberror = 0;
|
int liberror = 0;
|
||||||
|
|
||||||
string text;
|
string text;
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
#define RCW_TYPES_HPP
|
#define RCW_TYPES_HPP
|
||||||
|
|
||||||
#include <cstdlib> //size_t
|
#include <cstdlib> //size_t
|
||||||
#include <rexy/string.hpp>
|
#include <rexy/string_view.hpp>
|
||||||
|
|
||||||
namespace rcw{
|
namespace rcw{
|
||||||
|
|
||||||
@ -34,14 +34,14 @@ namespace rcw{
|
|||||||
class url
|
class url
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rexy::static_string<char> data;
|
rexy::string_view data;
|
||||||
|
|
||||||
explicit url(const char*, size_t len = 0);
|
explicit url(const char*, size_t len = 0);
|
||||||
};
|
};
|
||||||
class body
|
class body
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
rexy::static_string<char> data;
|
rexy::string_view data;
|
||||||
|
|
||||||
explicit body(const char*, size_t len = 0);
|
explicit body(const char*, size_t len = 0);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -35,7 +35,7 @@ namespace rcw{
|
|||||||
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
||||||
return std::async([=]() -> response
|
return std::async([=]() -> response
|
||||||
{
|
{
|
||||||
return get(rcw::url(*url_copy), *hlist);
|
return get(rcw::url(url_copy->data()), *hlist);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ namespace rcw{
|
|||||||
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
||||||
return std::async([=]() -> response
|
return std::async([=]() -> response
|
||||||
{
|
{
|
||||||
return post(rcw::url(*url_copy), rcw::body(*body_copy), *hlist);
|
return post(rcw::url(url_copy->data()), rcw::body(body_copy->data()), *hlist);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ namespace rcw{
|
|||||||
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
||||||
return std::async([=]() -> response
|
return std::async([=]() -> response
|
||||||
{
|
{
|
||||||
return put(rcw::url(*url_copy), rcw::body(*body_copy), *hlist);
|
return put(rcw::url(url_copy->data()), rcw::body(body_copy->data()), *hlist);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ namespace rcw{
|
|||||||
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
||||||
return std::async([=]() -> response
|
return std::async([=]() -> response
|
||||||
{
|
{
|
||||||
return del(rcw::url(*url_copy), *hlist);
|
return del(rcw::url(url_copy->data()), *hlist);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
std::future<response> async_del(const url& u, const body& b, std::initializer_list<header> headers){
|
std::future<response> async_del(const url& u, const body& b, std::initializer_list<header> headers){
|
||||||
@ -98,7 +98,7 @@ namespace rcw{
|
|||||||
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
std::shared_ptr<curl_header_list> hlist(new curl_header_list(headers));
|
||||||
return std::async([=]() -> response
|
return std::async([=]() -> response
|
||||||
{
|
{
|
||||||
return del(rcw::url(*url_copy), rcw::body(*body_copy), *hlist);
|
return del(rcw::url(url_copy->data()), rcw::body(body_copy->data()), *hlist);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -144,7 +144,7 @@ namespace rcw{
|
|||||||
curl_easy_getinfo(m_curl, CURLINFO_SIZE_DOWNLOAD_T, &x);
|
curl_easy_getinfo(m_curl, CURLINFO_SIZE_DOWNLOAD_T, &x);
|
||||||
retval.downloaded_bytes = x;
|
retval.downloaded_bytes = x;
|
||||||
curl_easy_getinfo(m_curl, CURLINFO_CONTENT_TYPE, &y);
|
curl_easy_getinfo(m_curl, CURLINFO_CONTENT_TYPE, &y);
|
||||||
retval.content_type = rexy::static_string<char>(y);
|
retval.content_type = rexy::string_view(y);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -162,45 +162,45 @@ namespace rcw{
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string curl_easy_handle::decode_to_std(const char* data, int len){
|
std::string curl_easy_handle::unescape_to_std(const char* data, int len){
|
||||||
char* tmp = decode_to_cstr(data, &len, len);
|
char* tmp = unescape_to_cstr(data, &len, len);
|
||||||
std::string ret(tmp, len);
|
std::string ret(tmp, len);
|
||||||
curl_free(tmp);
|
curl_free(tmp);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
char* curl_easy_handle::decode_to_cstr(const char* data, int* outlen, int len){
|
char* curl_easy_handle::unescape_to_cstr(const char* data, int* outlen, int len){
|
||||||
if(!len)
|
if(!len)
|
||||||
len = strlen(data);
|
len = strlen(data);
|
||||||
char* tmp = curl_easy_unescape(m_curl, data, len, outlen);
|
char* tmp = curl_easy_unescape(m_curl, data, len, outlen);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
string curl_easy_handle::escape_to_str(const char* data, int len){
|
string curl_easy_handle::escape(const char* data, int len){
|
||||||
char* tmp = escape_to_cstr(data, &len, len);
|
char* tmp = escape_to_cstr(data, &len, len);
|
||||||
return string(rexy::steal(tmp), len, len);
|
return string(rexy::steal(tmp), len, len);
|
||||||
}
|
}
|
||||||
string curl_easy_handle::escape_to_str(const rexy::string_base<char>& data){
|
string curl_easy_handle::escape(rexy::string_view data){
|
||||||
return escape_to_str(data.get(), data.length());
|
return escape(data.data(), data.length());
|
||||||
}
|
}
|
||||||
std::string curl_easy_handle::escape_to_std(const rexy::string_base<char>& data){
|
std::string curl_easy_handle::escape_to_std(rexy::string_view data){
|
||||||
return escape_to_std(data.get(), data.length());
|
return escape_to_std(data.data(), data.length());
|
||||||
}
|
}
|
||||||
char* curl_easy_handle::escape_to_cstr(const rexy::string_base<char>& data, int* outlen){
|
char* curl_easy_handle::escape_to_cstr(rexy::string_view data, int* outlen){
|
||||||
return escape_to_cstr(data.get(), outlen, data.length());
|
return escape_to_cstr(data.data(), outlen, data.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
string curl_easy_handle::decode_to_str(const char* data, int len){
|
string curl_easy_handle::unescape(const char* data, int len){
|
||||||
char* tmp = decode_to_cstr(data, &len, len);
|
char* tmp = unescape_to_cstr(data, &len, len);
|
||||||
return string(rexy::steal(tmp), len, len);
|
return string(rexy::steal(tmp), len, len);
|
||||||
}
|
}
|
||||||
string curl_easy_handle::decode_to_str(const rexy::string_base<char>& data){
|
string curl_easy_handle::unescape(rexy::string_view data){
|
||||||
return decode_to_str(data.get(), data.length());
|
return unescape(data.data(), data.length());
|
||||||
}
|
}
|
||||||
std::string curl_easy_handle::decode_to_std(const rexy::string_base<char>& data){
|
std::string curl_easy_handle::unescape_to_std(rexy::string_view data){
|
||||||
return decode_to_std(data.get(), data.length());
|
return unescape_to_std(data.data(), data.length());
|
||||||
}
|
}
|
||||||
char* curl_easy_handle::decode_to_cstr(const rexy::string_base<char>& data, int* outlen){
|
char* curl_easy_handle::unescape_to_cstr(rexy::string_view data, int* outlen){
|
||||||
return escape_to_cstr(data.get(), outlen, data.length());
|
return escape_to_cstr(data.data(), outlen, data.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,20 +20,20 @@
|
|||||||
|
|
||||||
namespace rcw{
|
namespace rcw{
|
||||||
|
|
||||||
http_status::http_status(long x):
|
httpint::httpint(long x):
|
||||||
m_code(x){}
|
m_code(x){}
|
||||||
http_status& http_status::operator=(long x){
|
httpint& httpint::operator=(long x){
|
||||||
m_code = x;
|
m_code = x;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool http_status::ok(void)const{
|
bool httpint::ok(void)const{
|
||||||
return (m_code >= 200 && m_code < 300);
|
return (m_code >= 200 && m_code < 300);
|
||||||
}
|
}
|
||||||
http_status::operator long(void)const{
|
httpint::operator long(void)const{
|
||||||
return m_code;
|
return m_code;
|
||||||
}
|
}
|
||||||
long http_status::get(void)const{
|
long httpint::get(void)const{
|
||||||
return m_code;
|
return m_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
src/sync.cpp
16
src/sync.cpp
@ -35,7 +35,7 @@ namespace rcw{
|
|||||||
c.set_header(headers);
|
c.set_header(headers);
|
||||||
c.set_read_data(nullptr);
|
c.set_read_data(nullptr);
|
||||||
c.set_write_data(cback);
|
c.set_write_data(cback);
|
||||||
c.set_url(u.data);
|
c.set_url(u.data.data());
|
||||||
return c.perform();
|
return c.perform();
|
||||||
}
|
}
|
||||||
response post_impl(curl_easy_handle& c, curl_cback_invoker* read_cback, curl_cback_invoker* write_cback, const url& u, const curl_header_list& headers){
|
response post_impl(curl_easy_handle& c, curl_cback_invoker* read_cback, curl_cback_invoker* write_cback, const url& u, const curl_header_list& headers){
|
||||||
@ -44,7 +44,7 @@ namespace rcw{
|
|||||||
c.set_read_fun(curl_read_callback);
|
c.set_read_fun(curl_read_callback);
|
||||||
c.set_read_data(read_cback);
|
c.set_read_data(read_cback);
|
||||||
c.set_write_data(write_cback);
|
c.set_write_data(write_cback);
|
||||||
c.set_url(u.data);
|
c.set_url(u.data.data());
|
||||||
c.set_header(headers);
|
c.set_header(headers);
|
||||||
return c.perform();
|
return c.perform();
|
||||||
}
|
}
|
||||||
@ -54,7 +54,7 @@ namespace rcw{
|
|||||||
c.set_read_fun(curl_read_callback);
|
c.set_read_fun(curl_read_callback);
|
||||||
c.set_read_data(read_cback);
|
c.set_read_data(read_cback);
|
||||||
c.set_write_data(write_cback);
|
c.set_write_data(write_cback);
|
||||||
c.set_url(u.data);
|
c.set_url(u.data.data());
|
||||||
c.set_header(headers);
|
c.set_header(headers);
|
||||||
return c.perform();
|
return c.perform();
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ namespace rcw{
|
|||||||
c.set_read_fun(curl_read_callback);
|
c.set_read_fun(curl_read_callback);
|
||||||
c.set_write_data(write_cback);
|
c.set_write_data(write_cback);
|
||||||
c.set_read_data(read_cback);
|
c.set_read_data(read_cback);
|
||||||
c.set_url(u.data);
|
c.set_url(u.data.data());
|
||||||
c.set_header(headers);
|
c.set_header(headers);
|
||||||
return c.perform();
|
return c.perform();
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ namespace rcw{
|
|||||||
c.set_write_fun(curl_write_callback);
|
c.set_write_fun(curl_write_callback);
|
||||||
c.set_write_data(write_cback);
|
c.set_write_data(write_cback);
|
||||||
c.set_read_data(nullptr);
|
c.set_read_data(nullptr);
|
||||||
c.set_url(u.data);
|
c.set_url(u.data.data());
|
||||||
c.set_header(headers);
|
c.set_header(headers);
|
||||||
return c.perform();
|
return c.perform();
|
||||||
}
|
}
|
||||||
@ -130,7 +130,7 @@ namespace rcw{
|
|||||||
return post(c, u, b, curl_header_list(headers));
|
return post(c, u, b, curl_header_list(headers));
|
||||||
}
|
}
|
||||||
response post(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
response post(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
||||||
default_curl_read_callback rcb{b.data.get(), b.data.length()};
|
default_curl_read_callback rcb{b.data.data(), b.data.length()};
|
||||||
default_curl_write_callback wcb{};
|
default_curl_write_callback wcb{};
|
||||||
response retval = post(c, rcb, wcb, u, headers);
|
response retval = post(c, rcb, wcb, u, headers);
|
||||||
retval.text = std::move(wcb.data);
|
retval.text = std::move(wcb.data);
|
||||||
@ -164,7 +164,7 @@ namespace rcw{
|
|||||||
return put(c, u, b, curl_header_list(headers));
|
return put(c, u, b, curl_header_list(headers));
|
||||||
}
|
}
|
||||||
response put(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
response put(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
||||||
default_curl_read_callback rcb{b.data.get(), b.data.length()};
|
default_curl_read_callback rcb{b.data.data(), b.data.length()};
|
||||||
default_curl_write_callback wcb{};
|
default_curl_write_callback wcb{};
|
||||||
response retval = put(c, rcb, wcb, u, headers);
|
response retval = put(c, rcb, wcb, u, headers);
|
||||||
retval.text = std::move(wcb.data);
|
retval.text = std::move(wcb.data);
|
||||||
@ -200,7 +200,7 @@ namespace rcw{
|
|||||||
return del(c, u, b, curl_header_list(headers));
|
return del(c, u, b, curl_header_list(headers));
|
||||||
}
|
}
|
||||||
response del(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
response del(curl_easy_handle& c, const url& u, const body& b, const curl_header_list& headers){
|
||||||
default_curl_read_callback rcb{b.data.get(), b.data.length()};
|
default_curl_read_callback rcb{b.data.data(), b.data.length()};
|
||||||
default_curl_write_callback wcb{};
|
default_curl_write_callback wcb{};
|
||||||
response retval = del(c, rcb, wcb, u, headers);
|
response retval = del(c, rcb, wcb, u, headers);
|
||||||
retval.text = std::move(wcb.data);
|
retval.text = std::move(wcb.data);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ void do_async_get(){
|
|||||||
rcw::response reply = f_reply.get();
|
rcw::response reply = f_reply.get();
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
void do_async_post(){
|
void do_async_post(){
|
||||||
PRINT_RUNNING_FUNC();
|
PRINT_RUNNING_FUNC();
|
||||||
@ -17,7 +17,7 @@ void do_async_post(){
|
|||||||
rcw::response reply = f_reply.get();
|
rcw::response reply = f_reply.get();
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
void do_async_put(){
|
void do_async_put(){
|
||||||
PRINT_RUNNING_FUNC();
|
PRINT_RUNNING_FUNC();
|
||||||
@ -25,7 +25,7 @@ void do_async_put(){
|
|||||||
rcw::response reply = f_reply.get();
|
rcw::response reply = f_reply.get();
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
void do_async_del(){
|
void do_async_del(){
|
||||||
PRINT_RUNNING_FUNC();
|
PRINT_RUNNING_FUNC();
|
||||||
@ -33,7 +33,7 @@ void do_async_del(){
|
|||||||
rcw::response reply = f_reply.get();
|
rcw::response reply = f_reply.get();
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|||||||
@ -8,7 +8,7 @@ void do_get(){
|
|||||||
rcw::response reply = rcw::get(rcw::url("https://httpbin.org/get"));
|
rcw::response reply = rcw::get(rcw::url("https://httpbin.org/get"));
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
void do_post(){
|
void do_post(){
|
||||||
@ -16,21 +16,21 @@ void do_post(){
|
|||||||
rcw::response reply = rcw::post(rcw::url("https://httpbin.org/post"));
|
rcw::response reply = rcw::post(rcw::url("https://httpbin.org/post"));
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
void do_put(){
|
void do_put(){
|
||||||
PRINT_RUNNING_FUNC();
|
PRINT_RUNNING_FUNC();
|
||||||
rcw::response reply = rcw::put(rcw::url("https://httpbin.org/put"));
|
rcw::response reply = rcw::put(rcw::url("https://httpbin.org/put"));
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
void do_del(){
|
void do_del(){
|
||||||
PRINT_RUNNING_FUNC();
|
PRINT_RUNNING_FUNC();
|
||||||
rcw::response reply = rcw::del(rcw::url("https://httpbin.org/delete"));
|
rcw::response reply = rcw::del(rcw::url("https://httpbin.org/delete"));
|
||||||
printf("%ld\n", reply.status.get());
|
printf("%ld\n", reply.status.get());
|
||||||
if(reply.ok())
|
if(reply.ok())
|
||||||
printf("%s\n", reply.text.get());
|
printf("%s\n", reply.text.data());
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user