arduino-audio-tools
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
HttpRequest Class Reference

Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient, but I did not manage to extract the mime type from streaming get requests. More...

#include <HttpRequest.h>

Inheritance diagram for HttpRequest:
BaseStream Stream Print

Public Member Functions

 HttpRequest ()
 
 HttpRequest (Client &client)
 
 ~HttpRequest ()
 
void addRequestHeader (const char *key, const char *value)
 Adds/Updates a request header.
 
int available () override
 
virtual int availableForWrite () override
 
virtual bool begin ()
 
Clientclient ()
 
virtual bool connected ()
 
size_t contentLength ()
 
virtual int del (Url &url, const char *mime=nullptr, const char *data=nullptr, int len=-1)
 http del
 
void end () override
 same as end()
 
virtual void flush () override
 
virtual int get (Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1)
 http get
 
const chargetReplyHeader (const char *key)
 
virtual int head (Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1)
 http head
 
virtual HttpRequestHeaderheader ()
 provides access to the request header
 
bool isChunked ()
 we are sending the data chunked
 
bool isReady ()
 
 operator bool ()
 
virtual int post (Url &url, const char *mime, const char *data, int len=-1)
 http post
 
virtual int post (Url &url, const char *mime, Stream &data, int len=-1)
 http post
 
virtual int process (MethodID action, Url &url, const char *mime, const char *data, int lenData=-1)
 
virtual int process (MethodID action, Url &url, const char *mime, Stream &stream, int len=-1)
 
virtual bool processBegin (MethodID action, Url &url, const char *mime, int lenData=-1)
 starts http request processing
 
virtual int processEnd ()
 Ends the http request processing and returns the status code or -1 on error.
 
virtual void processWrite (Stream &stream)
 Writes (Posts) the data of the indicated stream after calling processBegin.
 
virtual int put (Url &url, const char *mime, const char *data, int len=-1)
 http put
 
virtual int put (Url &url, const char *mime, Stream &data, int len=-1)
 http put
 
virtual int read (uint8_t *str, int len)
 
size_t readBytes (uint8_t *str, size_t len) override
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 
virtual int readln (uint8_t *str, int len, bool incl_nl=true)
 
virtual HttpReplyHeaderreply ()
 
virtual void setAcceptMime (const char *mime)
 
virtual void setAcceptsEncoding (const char *enc)
 
virtual void setAgent (const char *agent)
 Defines the agent.
 
void setClient (Client &client)
 
virtual void setConnection (const char *connection)
 
void setHost (const char *host)
 
void setOnConnectCallback (void(*callback)(HttpRequest &request, Url &url, HttpRequestHeader &request_header))
 Callback which allows you to add additional paramters dynamically.
 
void setTimeout (size_t timeoutMs)
 Defines the client timeout in ms.
 
void setWriteBufferSize (int size)
 
virtual void stop ()
 
size_t write (const uint8_t *data, size_t len) override
 
virtual size_t write (uint8_t ch) override
 

Protected Member Functions

virtual int connect (const char *ip, uint16_t port, int32_t timeout)
 
void refillReadBuffer ()
 Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()
 

Protected Attributes

int _timeout = 10
 
const characcept = ACCEPT_ALL
 
const characcept_encoding = IDENTITY
 
const charagent = nullptr
 
HttpChunkReader chunk_reader = HttpChunkReader(reply_header)
 
Clientclient_ptr = nullptr
 
int client_timeout = URL_CLIENT_TIMEOUT
 
const charconnection = CON_KEEP_ALIVE
 
const charhost_name = nullptr
 
void(* http_connect_callback )(HttpRequest &request, Url &url, HttpRequestHeader &request_header) = nullptr
 
bool is_chunked_output_active = false
 
bool is_ready = false
 
HttpReplyHeader reply_header
 
HttpRequestHeader request_header
 
RingBuffer< uint8_ttmp_in {0}
 
RingBuffer< uint8_ttmp_out {0}
 
Url url
 
int write_buffer_size = MAX_SINGLE_CHARS
 

Detailed Description

Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient, but I did not manage to extract the mime type from streaming get requests.

The functionality is based on the Arduino Client class.

Author
Phil Schatzmann

Constructor & Destructor Documentation

◆ HttpRequest() [1/2]

HttpRequest ( )
inline

◆ ~HttpRequest()

~HttpRequest ( )
inline

◆ HttpRequest() [2/2]

HttpRequest ( Client client)
inline

Member Function Documentation

◆ addRequestHeader()

void addRequestHeader ( const char key,
const char value 
)
inline

Adds/Updates a request header.

◆ available()

int available ( )
inlineoverridevirtual

Reimplemented from BaseStream.

◆ availableForWrite()

virtual int availableForWrite ( )
inlineoverridevirtualinherited

◆ begin()

virtual bool begin ( )
inlinevirtualinherited

◆ client()

Client & client ( )
inline

◆ connect()

virtual int connect ( const char ip,
uint16_t  port,
int32_t  timeout 
)
inlineprotectedvirtual

◆ connected()

virtual bool connected ( )
inlinevirtual

◆ contentLength()

size_t contentLength ( )
inline

◆ del()

virtual int del ( Url url,
const char mime = nullptr,
const char data = nullptr,
int  len = -1 
)
inlinevirtual

http del

◆ end()

void end ( )
inlineoverridevirtual

same as end()

Reimplemented from BaseStream.

◆ flush()

virtual void flush ( )
inlineoverridevirtualinherited

◆ get()

virtual int get ( Url url,
const char acceptMime = nullptr,
const char data = nullptr,
int  len = -1 
)
inlinevirtual

http get

◆ getReplyHeader()

const char * getReplyHeader ( const char key)
inline

◆ head()

virtual int head ( Url url,
const char acceptMime = nullptr,
const char data = nullptr,
int  len = -1 
)
inlinevirtual

http head

◆ header()

virtual HttpRequestHeader & header ( )
inlinevirtual

provides access to the request header

◆ isChunked()

bool isChunked ( )
inline

we are sending the data chunked

◆ isReady()

bool isReady ( )
inline

returns true when the request has completed and ready for the data to be requested

◆ operator bool()

operator bool ( )
inline

◆ post() [1/2]

virtual int post ( Url url,
const char mime,
const char data,
int  len = -1 
)
inlinevirtual

http post

◆ post() [2/2]

virtual int post ( Url url,
const char mime,
Stream data,
int  len = -1 
)
inlinevirtual

http post

◆ process() [1/2]

virtual int process ( MethodID  action,
Url url,
const char mime,
const char data,
int  lenData = -1 
)
inlinevirtual

◆ process() [2/2]

virtual int process ( MethodID  action,
Url url,
const char mime,
Stream stream,
int  len = -1 
)
inlinevirtual

◆ processBegin()

virtual bool processBegin ( MethodID  action,
Url url,
const char mime,
int  lenData = -1 
)
inlinevirtual

starts http request processing

◆ processEnd()

virtual int processEnd ( )
inlinevirtual

Ends the http request processing and returns the status code or -1 on error.

◆ processWrite()

virtual void processWrite ( Stream stream)
inlinevirtual

Writes (Posts) the data of the indicated stream after calling processBegin.

◆ put() [1/2]

virtual int put ( Url url,
const char mime,
const char data,
int  len = -1 
)
inlinevirtual

http put

◆ put() [2/2]

virtual int put ( Url url,
const char mime,
Stream data,
int  len = -1 
)
inlinevirtual

http put

◆ read()

virtual int read ( uint8_t str,
int  len 
)
inlinevirtual

◆ readBytes()

size_t readBytes ( uint8_t str,
size_t  len 
)
inlineoverridevirtual

Implements BaseStream.

◆ readBytesUntil()

size_t readBytesUntil ( char  terminator,
char buffer,
size_t  length 
)
inline

◆ readln()

virtual int readln ( uint8_t str,
int  len,
bool  incl_nl = true 
)
inlinevirtual

◆ refillReadBuffer()

void refillReadBuffer ( )
inlineprotectedinherited

Refill small read buffer (e.g. 8 bytes) to avoid single byte reads when calling read()

◆ reply()

virtual HttpReplyHeader & reply ( )
inlinevirtual

◆ setAcceptMime()

virtual void setAcceptMime ( const char mime)
inlinevirtual

◆ setAcceptsEncoding()

virtual void setAcceptsEncoding ( const char enc)
inlinevirtual

◆ setAgent()

virtual void setAgent ( const char agent)
inlinevirtual

Defines the agent.

◆ setClient()

void setClient ( Client client)
inline

◆ setConnection()

virtual void setConnection ( const char connection)
inlinevirtual

◆ setHost()

void setHost ( const char host)
inline

◆ setOnConnectCallback()

void setOnConnectCallback ( void(*)(HttpRequest &request, Url &url, HttpRequestHeader &request_header callback)
inline

Callback which allows you to add additional paramters dynamically.

◆ setTimeout()

void setTimeout ( size_t  timeoutMs)
inline

Defines the client timeout in ms.

◆ setWriteBufferSize()

void setWriteBufferSize ( int  size)
inlineinherited

◆ stop()

virtual void stop ( )
inlinevirtual

◆ write() [1/2]

size_t write ( const uint8_t data,
size_t  len 
)
inlineoverridevirtual

Write data to the client: can be used to post data after calling processBegin

Implements BaseStream.

◆ write() [2/2]

virtual size_t write ( uint8_t  ch)
inlineoverridevirtualinherited

Member Data Documentation

◆ _timeout

int _timeout = 10
protectedinherited

◆ accept

const char* accept = ACCEPT_ALL
protected

◆ accept_encoding

const char* accept_encoding = IDENTITY
protected

◆ agent

const char* agent = nullptr
protected

◆ chunk_reader

HttpChunkReader chunk_reader = HttpChunkReader(reply_header)
protected

◆ client_ptr

Client* client_ptr = nullptr
protected

◆ client_timeout

int client_timeout = URL_CLIENT_TIMEOUT
protected

◆ connection

const char* connection = CON_KEEP_ALIVE
protected

◆ host_name

const char* host_name = nullptr
protected

◆ http_connect_callback

void(* http_connect_callback) (HttpRequest &request, Url &url, HttpRequestHeader &request_header) = nullptr
protected

◆ is_chunked_output_active

bool is_chunked_output_active = false
protected

◆ is_ready

bool is_ready = false
protected

◆ reply_header

HttpReplyHeader reply_header
protected

◆ request_header

HttpRequestHeader request_header
protected

◆ tmp_in

RingBuffer<uint8_t> tmp_in {0}
protectedinherited

◆ tmp_out

RingBuffer<uint8_t> tmp_out {0}
protectedinherited

◆ url

Url url
protected

◆ write_buffer_size

int write_buffer_size = MAX_SINGLE_CHARS
protectedinherited

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