Arduino DLNA Server
HttpTunnel.h
Go to the documentation of this file.
1 #pragma once
2 #include "HttpRequest.h"
3 #include "basic/Url.h"
4 
5 namespace tiny_dlna {
6 
12 class HttpTunnel {
13  public:
14  HttpTunnel(const char* url, const char* mime = "text/html") {
15  DlnaLogger.log(DlnaInfo, "HttpTunnel: %s", url);
16  v_url.setUrl(url);
17  v_mime = mime;
18  }
19 
21  Stream* get() {
22  DlnaLogger.log(DlnaInfo, "HttpTunnel::get");
23  if (isOk(v_request.get(v_url, v_mime))) {
24  return v_request.client();
25  }
26  return nullptr;
27  }
28 
29  HttpRequest& request() { return v_request; }
30 
31  const char* mime() { return v_mime; }
32 
33  protected:
36  const char* v_mime;
37 
38  bool isOk(int code) { return code >= 200 && code < 300; }
39 };
40 
41 } // namespace tiny_dlna
Simple API to process get, put, post, del http requests I tried to use Arduino HttpClient,...
Definition: HttpRequest.h:21
virtual int get(Url &url, const char *acceptMime=nullptr, const char *data=nullptr, int len=-1)
Definition: HttpRequest.h:75
Client * client()
Definition: HttpRequest.h:123
Forwards a request to a destination URL and provides a pointer to the result stream.
Definition: HttpTunnel.h:12
bool isOk(int code)
Definition: HttpTunnel.h:38
HttpRequest v_request
Definition: HttpTunnel.h:35
Url v_url
Definition: HttpTunnel.h:34
Stream * get()
Executes the get request.
Definition: HttpTunnel.h:21
const char * mime()
Definition: HttpTunnel.h:31
const char * v_mime
Definition: HttpTunnel.h:36
HttpRequest & request()
Definition: HttpTunnel.h:29
HttpTunnel(const char *url, const char *mime="text/html")
Definition: HttpTunnel.h:14
void log(DlnaLogLevel current_level, const char *fmt...)
Print log message.
Definition: Logger.h:40
URL parser which breaks a full url string up into its individual parts.
Definition: Url.h:18
void setUrl(const char *url)
Definition: Url.h:53
Definition: Allocator.h:6
@ DlnaInfo
Definition: Logger.h:16
LoggerClass DlnaLogger
Definition: Logger.cpp:5