Arduino DLNA Server
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
tiny_dlna::HttpRequest< ClientType > Class Template 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 tiny_dlna::HttpRequest< ClientType >:
Inheritance graph
[legend]

Public Member Functions

 HttpRequest ()
 Default constructor.
 
 HttpRequest (ClientType &client)
 Constructor with specified client.
 
 ~HttpRequest () override
 Destructor.
 
void setClient (Client &client) override
 Sets the client to be used for the requests.
 
void setHost (const char *host) override
 Sets the host name for the requests.
 
 operator bool () override
 Checks if the request is valid.
 
bool connected () override
 Checks if connected to the server.
 
int available () override
 Returns the number of available bytes to read.
 
void stop () override
 Stops the connection.
 
int post (Url &url, const char *mime, const char *data, int len=-1) override
 Sends a POST request with data.
 
int post (Url &url, size_t len, std::function< size_t(Print &, void *)> writer, const char *mime=nullptr, void *ref=nullptr) override
 Sends a POST request with streaming body.
 
int notify (Url &url, std::function< size_t(Print &, void *)> writer, const char *mime=nullptr, void *ref=nullptr) override
 Sends a NOTIFY request with streaming body.
 
int put (Url &url, const char *mime, const char *data, int len=-1) override
 Sends a PUT request.
 
int del (Url &url, const char *mime=nullptr, const char *data=nullptr, int len=-1) override
 Sends a DELETE request.
 
int get (Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1) override
 Sends a GET request.
 
int head (Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1) override
 Sends a HEAD request.
 
int subscribe (Url &url) override
 Sends a SUBSCRIBE request.
 
int unsubscribe (Url &url, const char *sid) override
 Sends an UNSUBSCRIBE request.
 
int read (uint8_t *str, int len) override
 Reads reply data.
 
int readln (uint8_t *str, int len, bool incl_nl=true) override
 Reads reply data up to the next new line.
 
HttpReplyHeaderreply () override
 Returns the reply header.
 
HttpRequestHeaderrequest () override
 Returns the request header.
 
void setAgent (const char *agent) override
 Sets the user agent.
 
void setConnection (const char *connection) override
 Sets the connection type.
 
void setAcceptsEncoding (const char *enc) override
 Sets the accepted encodings.
 
Client * client () override
 Returns the client pointer.
 
void setTimeout (int ms) override
 Sets the timeout.
 

Protected Member Functions

const char * str (const char *in)
 Returns an empty string if input is null, otherwise returns the input.
 
virtual int connect (const char *ip, uint16_t port)
 opens a connection to the indicated host
 
virtual int process (TinyMethodID action, Url &url, const char *mime, const char *data, int len=-1)
 sends request and reads the reply_header from the server
 
virtual int process (TinyMethodID method, Url &url, size_t len, std::function< size_t(Print &, void *)> writer, const char *mime=nullptr, void *ref=nullptr)
 

Protected Attributes

ClientType default_client
 
Client * client_ptr = nullptr
 
Url url
 
HttpRequestHeader request_header
 
HttpReplyHeader reply_header
 
HttpChunkReader chunk_reader {reply_header}
 
Str host_name
 
const char * agent = nullptr
 
const char * connection = CON_CLOSE
 
const char * accept = ACCEPT_ALL
 
const char * accept_encoding = nullptr
 

Detailed Description

template<typename ClientType>
class tiny_dlna::HttpRequest< ClientType >

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. The template parameter defines the concrete client that will be managed (e.g. WiFiClient); callers must now provide it explicitly.

Template Parameters
ClientTypeconcrete Arduino client type that implements the Client interface (e.g. WiFiClient, EthernetClient).

Constructor & Destructor Documentation

◆ HttpRequest() [1/2]

template<typename ClientType >
tiny_dlna::HttpRequest< ClientType >::HttpRequest ( )
inline

Default constructor.

◆ HttpRequest() [2/2]

template<typename ClientType >
tiny_dlna::HttpRequest< ClientType >::HttpRequest ( ClientType &  client)
inlineexplicit

Constructor with specified client.

◆ ~HttpRequest()

template<typename ClientType >
tiny_dlna::HttpRequest< ClientType >::~HttpRequest ( )
inlineoverride

Destructor.

Member Function Documentation

◆ available()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::available ( )
inlineoverridevirtual

Returns the number of available bytes to read.

Implements tiny_dlna::IHttpRequest.

◆ client()

template<typename ClientType >
Client * tiny_dlna::HttpRequest< ClientType >::client ( )
inlineoverridevirtual

Returns the client pointer.

Implements tiny_dlna::IHttpRequest.

◆ connect()

template<typename ClientType >
virtual int tiny_dlna::HttpRequest< ClientType >::connect ( const char *  ip,
uint16_t  port 
)
inlineprotectedvirtual

opens a connection to the indicated host

◆ connected()

template<typename ClientType >
bool tiny_dlna::HttpRequest< ClientType >::connected ( )
inlineoverridevirtual

Checks if connected to the server.

Implements tiny_dlna::IHttpRequest.

◆ del()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::del ( Url url,
const char *  mime = nullptr,
const char *  data = nullptr,
int  len = -1 
)
inlineoverridevirtual

Sends a DELETE request.

Implements tiny_dlna::IHttpRequest.

◆ get()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::get ( Url url,
const char *  acceptMime = nullptr,
const char *  data = nullptr,
int  len = -1 
)
inlineoverridevirtual

Sends a GET request.

Implements tiny_dlna::IHttpRequest.

◆ head()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::head ( Url url,
const char *  acceptMime = nullptr,
const char *  data = nullptr,
int  len = -1 
)
inlineoverridevirtual

Sends a HEAD request.

Implements tiny_dlna::IHttpRequest.

◆ notify()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::notify ( Url url,
std::function< size_t(Print &, void *)>  writer,
const char *  mime = nullptr,
void *  ref = nullptr 
)
inlineoverridevirtual

Sends a NOTIFY request with streaming body.

Implements tiny_dlna::IHttpRequest.

◆ operator bool()

template<typename ClientType >
tiny_dlna::HttpRequest< ClientType >::operator bool ( )
inlineoverridevirtual

Checks if the request is valid.

Implements tiny_dlna::IHttpRequest.

◆ post() [1/2]

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::post ( Url url,
const char *  mime,
const char *  data,
int  len = -1 
)
inlineoverridevirtual

Sends a POST request with data.

Implements tiny_dlna::IHttpRequest.

◆ post() [2/2]

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::post ( Url url,
size_t  len,
std::function< size_t(Print &, void *)>  writer,
const char *  mime = nullptr,
void *  ref = nullptr 
)
inlineoverridevirtual

Sends a POST request with streaming body.

Implements tiny_dlna::IHttpRequest.

◆ process() [1/2]

template<typename ClientType >
virtual int tiny_dlna::HttpRequest< ClientType >::process ( TinyMethodID  action,
Url url,
const char *  mime,
const char *  data,
int  len = -1 
)
inlineprotectedvirtual

sends request and reads the reply_header from the server

◆ process() [2/2]

template<typename ClientType >
virtual int tiny_dlna::HttpRequest< ClientType >::process ( TinyMethodID  method,
Url url,
size_t  len,
std::function< size_t(Print &, void *)>  writer,
const char *  mime = nullptr,
void *  ref = nullptr 
)
inlineprotectedvirtual

Shared implementation for streaming requests. Both POST and NOTIFY (and potentially others) can use this to avoid code duplication.

◆ put()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::put ( Url url,
const char *  mime,
const char *  data,
int  len = -1 
)
inlineoverridevirtual

Sends a PUT request.

Implements tiny_dlna::IHttpRequest.

◆ read()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::read ( uint8_t *  str,
int  len 
)
inlineoverridevirtual

Reads reply data.

Implements tiny_dlna::IHttpRequest.

◆ readln()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::readln ( uint8_t *  str,
int  len,
bool  incl_nl = true 
)
inlineoverridevirtual

Reads reply data up to the next new line.

Implements tiny_dlna::IHttpRequest.

◆ reply()

template<typename ClientType >
HttpReplyHeader & tiny_dlna::HttpRequest< ClientType >::reply ( )
inlineoverridevirtual

Returns the reply header.

Implements tiny_dlna::IHttpRequest.

◆ request()

template<typename ClientType >
HttpRequestHeader & tiny_dlna::HttpRequest< ClientType >::request ( )
inlineoverridevirtual

Returns the request header.

Implements tiny_dlna::IHttpRequest.

◆ setAcceptsEncoding()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setAcceptsEncoding ( const char *  enc)
inlineoverridevirtual

Sets the accepted encodings.

Implements tiny_dlna::IHttpRequest.

◆ setAgent()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setAgent ( const char *  agent)
inlineoverridevirtual

Sets the user agent.

Implements tiny_dlna::IHttpRequest.

◆ setClient()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setClient ( Client &  client)
inlineoverridevirtual

Sets the client to be used for the requests.

Implements tiny_dlna::IHttpRequest.

◆ setConnection()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setConnection ( const char *  connection)
inlineoverridevirtual

Sets the connection type.

Implements tiny_dlna::IHttpRequest.

◆ setHost()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setHost ( const char *  host)
inlineoverridevirtual

Sets the host name for the requests.

Implements tiny_dlna::IHttpRequest.

◆ setTimeout()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::setTimeout ( int  ms)
inlineoverridevirtual

Sets the timeout.

Implements tiny_dlna::IHttpRequest.

◆ stop()

template<typename ClientType >
void tiny_dlna::HttpRequest< ClientType >::stop ( )
inlineoverridevirtual

Stops the connection.

Implements tiny_dlna::IHttpRequest.

◆ str()

template<typename ClientType >
const char * tiny_dlna::HttpRequest< ClientType >::str ( const char *  in)
inlineprotected

Returns an empty string if input is null, otherwise returns the input.

◆ subscribe()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::subscribe ( Url url)
inlineoverridevirtual

Sends a SUBSCRIBE request.

Implements tiny_dlna::IHttpRequest.

◆ unsubscribe()

template<typename ClientType >
int tiny_dlna::HttpRequest< ClientType >::unsubscribe ( Url url,
const char *  sid 
)
inlineoverridevirtual

Sends an UNSUBSCRIBE request.

Implements tiny_dlna::IHttpRequest.

Member Data Documentation

◆ accept

template<typename ClientType >
const char* tiny_dlna::HttpRequest< ClientType >::accept = ACCEPT_ALL
protected

◆ accept_encoding

template<typename ClientType >
const char* tiny_dlna::HttpRequest< ClientType >::accept_encoding = nullptr
protected

◆ agent

template<typename ClientType >
const char* tiny_dlna::HttpRequest< ClientType >::agent = nullptr
protected

◆ chunk_reader

template<typename ClientType >
HttpChunkReader tiny_dlna::HttpRequest< ClientType >::chunk_reader {reply_header}
protected

◆ client_ptr

template<typename ClientType >
Client* tiny_dlna::HttpRequest< ClientType >::client_ptr = nullptr
protected

◆ connection

template<typename ClientType >
const char* tiny_dlna::HttpRequest< ClientType >::connection = CON_CLOSE
protected

◆ default_client

template<typename ClientType >
ClientType tiny_dlna::HttpRequest< ClientType >::default_client
protected

◆ host_name

template<typename ClientType >
Str tiny_dlna::HttpRequest< ClientType >::host_name
protected

◆ reply_header

template<typename ClientType >
HttpReplyHeader tiny_dlna::HttpRequest< ClientType >::reply_header
protected

◆ request_header

template<typename ClientType >
HttpRequestHeader tiny_dlna::HttpRequest< ClientType >::request_header
protected

◆ url

template<typename ClientType >
Url tiny_dlna::HttpRequest< ClientType >::url
protected

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