Nebula
Loading...
Searching...
No Matches
curlhttpclient.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
15#include "core/config.h"
16#include "core/refcounted.h"
17#include "http/httpstatus.h"
18#include "http/httpmethod.h"
19#include "io/uri.h"
20#include "io/stream.h"
21
22#ifdef USE_CURL
23//------------------------------------------------------------------------------
24namespace Http
25{
26class CurlHttpClient : public Core::RefCounted
27{
28 __DeclareClass(CurlHttpClient);
29public:
31 CurlHttpClient();
33 virtual ~CurlHttpClient();
34
36 void SetUserAgent(const Util::String& userAgent);
38 const Util::String& GetUserAgent() const;
39
41 bool Connect(const IO::URI& uri);
43 void Disconnect();
45 bool IsConnected() const;
46
48 HttpStatus::Code SendRequest(HttpMethod::Code requestMethod, const IO::URI& uri, const Ptr<IO::Stream>& responseContentStream);
50 HttpStatus::Code SendRequest(HttpMethod::Code requestMethod, const IO::URI& uri, const Util::String & body, const Ptr<IO::Stream>& responseContentStream);
51private:
52 Util::String userAgent;
53 void* curlSession;
54 char* curlErrorBuffer;
55
57 static size_t CurlWriteDataCallback(char* ptr, size_t size, size_t nmemb, void* userData);
59 static size_t CurlHeaderCallback(char* ptr, size_t size, size_t nmenb, void* userData);
60};
61
62//------------------------------------------------------------------------------
65inline void
66CurlHttpClient::SetUserAgent(const Util::String& agent)
67{
68 this->userAgent = agent;
69}
70
71//------------------------------------------------------------------------------
74inline const Util::String&
75CurlHttpClient::GetUserAgent() const
76{
77 return this->userAgent;
78}
79
80} // namespace Http
81//------------------------------------------------------------------------------
82#endif
The common base class of Nebula.
Definition refcounted.h:38
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Nebula compiler specific defines and configuration.
This file was generated with Nebula Trifid's idlc compiler tool.
Definition defaulthttprequesthandler.cc:15
#define __DeclareClass(type)
Nebula's universal string class.
Definition string.h:50