add http_client library, using libcurl
take out common http entities to http_common dir
This commit is contained in:
61
libs/main/http_client/pihttpclient.h
Normal file
61
libs/main/http_client/pihttpclient.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#ifndef pihttpclient_h
|
||||
#define pihttpclient_h
|
||||
|
||||
#include "pihttptypes.h"
|
||||
#include "pip_http_client_export.h"
|
||||
|
||||
|
||||
class PIHTTPClientBase {
|
||||
public:
|
||||
int __infoFunc(ssize_t dltotal, ssize_t dlnow, ssize_t ultotal, ssize_t ulnow);
|
||||
int __debugFunc(int type, char * data, size_t size);
|
||||
};
|
||||
|
||||
|
||||
class PIP_HTTP_CLIENT_EXPORT PIHTTPClient: private PIHTTPClientBase {
|
||||
friend class PIHTTPClientBase;
|
||||
friend class CurlThreadPool;
|
||||
|
||||
public:
|
||||
static PIHTTPClient * create(const PIString & url, PIHTTP::Method method = PIHTTP::Method::Get, const PIHTTP::MessageConst & req = {});
|
||||
|
||||
PIHTTPClient * onFinish(std::function<void()> f);
|
||||
PIHTTPClient * onFinish(std::function<void(const PIHTTP::MessageConst &)> f);
|
||||
PIHTTPClient * onError(std::function<void()> f);
|
||||
PIHTTPClient * onError(std::function<void(const PIHTTP::MessageConst &)> f);
|
||||
PIHTTPClient * onAbort(std::function<void()> f);
|
||||
PIHTTPClient * onAbort(std::function<void(const PIHTTP::MessageConst &)> f);
|
||||
|
||||
void start();
|
||||
void abort();
|
||||
|
||||
PIString lastError() const { return last_error; }
|
||||
|
||||
private:
|
||||
NO_COPY_CLASS(PIHTTPClient)
|
||||
PIHTTPClient();
|
||||
virtual ~PIHTTPClient();
|
||||
|
||||
PRIVATE_DECLARATION(PIP_HTTP_CLIENT_EXPORT)
|
||||
|
||||
bool init();
|
||||
void perform();
|
||||
void procHeaderLine(PIString & line);
|
||||
|
||||
static size_t writeMemoryFunc(void * contents, size_t size, size_t nmemb, void * ptr);
|
||||
static size_t readMemoryFunc(void * contents, size_t size, size_t nmemb, void * ptr);
|
||||
static size_t headerFunc(char * contents, size_t size, size_t nmemb, void * ptr);
|
||||
int infoFunc(ssize_t dltotal, ssize_t dlnow, ssize_t ultotal, ssize_t ulnow);
|
||||
int debugFunc(int type, char * data, size_t size);
|
||||
|
||||
PIString url;
|
||||
PIString last_error;
|
||||
PIByteArray buffer_out;
|
||||
PIHTTP::MessageMutable request, reply;
|
||||
std::atomic_bool is_cancel = {false};
|
||||
ssize_t read_pos = 0;
|
||||
std::function<void(const PIHTTP::MessageConst &)> on_finish, on_error, on_abort;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
54
libs/main/http_client/pihttpclientmodule.h
Normal file
54
libs/main/http_client/pihttpclientmodule.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
PIP - Platform Independent Primitives
|
||||
Module includes
|
||||
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
//! \defgroup HTTPServer HTTPServer
|
||||
//! \~\brief
|
||||
//! \~english HTTP client
|
||||
//! \~russian HTTP сервер
|
||||
//!
|
||||
//! \~\details
|
||||
//! \~english \section cmake_module_HTTPServer Building with CMake
|
||||
//! \~russian \section cmake_module_HTTPServer Сборка с использованием CMake
|
||||
//!
|
||||
//! \~\code
|
||||
//! find_package(PIP REQUIRED)
|
||||
//! target_link_libraries([target] PIP::HTTPServer)
|
||||
//! \endcode
|
||||
//!
|
||||
//! \~english \par Common
|
||||
//! \~russian \par Общее
|
||||
//!
|
||||
//! \~english
|
||||
//! These files provides HTTP server based on libmicrohttpd
|
||||
//!
|
||||
//! \~russian
|
||||
//! Эти файлы обеспечивают HTTP сервер, основанный на libmicrohttpd
|
||||
//!
|
||||
//! \~\authors
|
||||
//! \~english
|
||||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||
//! \~russian
|
||||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||
//!
|
||||
|
||||
#ifndef pihttpclientmodule_H
|
||||
#define pihttpclientmodule_H
|
||||
|
||||
#include "pihttpclient.h"
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user