Trippin Cyril
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
trippingcyril::net::http::SimpleHTTPSocket Class Reference

A simple http client. More...

#include <SimpleHTTPSocket.h>

Inheritance diagram for trippingcyril::net::http::SimpleHTTPSocket:
[legend]
Collaboration diagram for trippingcyril::net::http::SimpleHTTPSocket:
[legend]

Public Member Functions

 SimpleHTTPSocket (const Module *module, HTTPCallback *callback=NULL)
 
 SimpleHTTPSocket (const Module *module, const HTTPLamdbaCallback &callback, const HTTPLamdbaErrorCallback &errorcallback=nullptr)
 
virtual ~SimpleHTTPSocket ()
 
bool Get (const String &url)
 
bool Post (const String &url, const String &postData, const String &type="")
 
bool Patch (const String &url, const String &patchData, const String &type="")
 
bool Put (const String &url, const String &putData, const String &type="")
 
bool Delete (const String &url, const String &deleteData, const String &type="")
 
void setExtraHeader (const String &key, const String &value)
 
String getURL () const
 
- Public Member Functions inherited from trippingcyril::net::Socket
 Socket (const Module *module)
 
 Socket (struct bufferevent *event)
 
virtual ~Socket ()
 
void Close () override
 
bool Connect (const String &hostname, uint16_t port, bool ssl=false, double timeout=60.0)
 
bool Connect (const IPAddress *ip, uint16_t port, bool ssl=false, double timeout=60.0)
 
int Write (const char *data, size_t len) override
 
void SetReadLine (bool b)
 
bool IsConnected () const
 
void SetTimeout (double timeout)
 
void DisableTimeout ()
 
const IPAddressGetIP () const
 
- Public Member Functions inherited from trippingcyril::trippingcyril::Event
 Event (const Module *module)
 
virtual ~Event ()
 
const ModuleGetModule () const
 
- Public Member Functions inherited from trippingcyril::Writer
int WriteString (const String &data)
 
virtual bool shouldDelete () const override
 

Static Public Attributes

static const int DECOMPESSION_ERROR = -1
 
static const int TIMEOUT = -2
 
static const int GOT_RESPONSE_TOO_EARLY = -3
 
- Static Public Attributes inherited from trippingcyril::Writer
static const int BUFFER_SIZE
 

Protected Member Functions

void Connected () override
 
void Disconnected () override
 
void Timeout () override
 
- Protected Member Functions inherited from trippingcyril::net::Socket
virtual size_t ReadData (const char *data, size_t len)
 
virtual void ReadLine (const String &line)
 
virtual void OnWrite (size_t bytes_left)
 
bool SetTCPNoDelay (bool enable)
 
bool SetTCPKeepAlive (bool enable, int delay)
 
- Protected Member Functions inherited from trippingcyril::trippingcyril::Event
event_base * GetEventBase () const
 
evdns_base * GetDNSBase () const
 

Additional Inherited Members

- Protected Attributes inherited from trippingcyril::net::Socket
uint8_t read_more: 1
 
size_t next_read
 
- Protected Attributes inherited from trippingcyril::trippingcyril::Event
const Modulemodule
 

Detailed Description

A simple http client.

Constructor & Destructor Documentation

trippingcyril::net::http::SimpleHTTPSocket::SimpleHTTPSocket ( const Module module,
HTTPCallback callback = NULL 
)

General constructor and the place to register your callback

trippingcyril::net::http::SimpleHTTPSocket::SimpleHTTPSocket ( const Module module,
const HTTPLamdbaCallback callback,
const HTTPLamdbaErrorCallback errorcallback = nullptr 
)

General constructor that uses lamdba functions instead of a general callback

Note
Requires C++11
virtual trippingcyril::net::http::SimpleHTTPSocket::~SimpleHTTPSocket ( )
virtual

Deconstructor

Member Function Documentation

void trippingcyril::net::http::SimpleHTTPSocket::Connected ( )
overrideprotectedvirtual

Connected event from the Socket class, make sure to call this implemention in case of overriding this class as it sends of the actual request etc.

Reimplemented from trippingcyril::net::Socket.

bool trippingcyril::net::http::SimpleHTTPSocket::Delete ( const String url,
const String deleteData,
const String type = "" 
)

Do a simple HTTP DELETE request

Parameters
urlThe url to request
deleteDatathe raw put data to send
typeThe Content-Type header to set
Returns
True if url was succesfully parsed and the request is started
void trippingcyril::net::http::SimpleHTTPSocket::Disconnected ( )
overrideprotectedvirtual

Disconnected event from the Socket class, make sure to call this implemention in case of overriding this class as it may call one of the HTTPCallback methods.

Reimplemented from trippingcyril::net::Socket.

bool trippingcyril::net::http::SimpleHTTPSocket::Get ( const String url)

Do a simple HTTP GET request

Parameters
urlThe url to request
Returns
True if url was succesfully parsed and the request is started
String trippingcyril::net::http::SimpleHTTPSocket::getURL ( ) const
inline
Returns
The url requested
bool trippingcyril::net::http::SimpleHTTPSocket::Patch ( const String url,
const String patchData,
const String type = "" 
)

Do a simple HTTP PATCH request

Parameters
urlThe url to request
patchDatathe raw patch data to send
typeThe Content-Type header to set
Returns
True if url was succesfully parsed and the request is started
bool trippingcyril::net::http::SimpleHTTPSocket::Post ( const String url,
const String postData,
const String type = "" 
)

Do a simple HTTP POST request

Parameters
urlThe url to request
postDataThe raw post data to send
typeThe Content-Type header to set
Returns
True if url was succesfully parsed and the request is started
bool trippingcyril::net::http::SimpleHTTPSocket::Put ( const String url,
const String putData,
const String type = "" 
)

Do a simple HTTP PUT request

Parameters
urlThe url to request
putDatathe raw put data to send
typeThe Content-Type header to set
Returns
True if url was succesfully parsed and the request is started
void trippingcyril::net::http::SimpleHTTPSocket::setExtraHeader ( const String key,
const String value 
)
inline

Set any custom headers to send with our request, must be called before Get() or Post()

Parameters
keyThe key for your custom header
valueThe value for your custom header
void trippingcyril::net::http::SimpleHTTPSocket::Timeout ( )
overrideprotectedvirtual

Timeout event from the Socket class.

See Also
TIMEOUT

Reimplemented from trippingcyril::net::Socket.

Member Data Documentation

const int trippingcyril::net::http::SimpleHTTPSocket::DECOMPESSION_ERROR = -1
static

Error code in case of any decompression errors. In case you see this error often please report a bug over at https://github.com/schoentoon/tripping-cyril/issues

See Also
HTTPCallback::OnRequestError
const int trippingcyril::net::http::SimpleHTTPSocket::GOT_RESPONSE_TOO_EARLY = -3
static

Error code for when we get a response before we sent out our full request, which of course shouldn't be happening!

const int trippingcyril::net::http::SimpleHTTPSocket::TIMEOUT = -2
static

Error code in case of a general socket timeout.

See Also
HTTPCallback::OnRequestError
Socket::Timeout

The documentation for this class was generated from the following file: