Lolly 1.4.28
Loading...
Searching...
No Matches
Typedefs | Enumerations | Functions | Variables
lolly::io Namespace Reference

Typedefs

typedef lolly_tree< blackboxhttp_tree
 
using http_headers = hashmap<string, string>
 

Enumerations

enum  http_label : int {
  STATUS_CODE = 1 , TEXT , URL , ELAPSED ,
  HEADER , PARAMETERS , PAYLOAD , MULTIPART ,
  TUPLE , ROOT
}
 

Functions

template<typename T >
http_tree blackbox_tree (int label, T data)
 
static http_tree response_to_tree (cpr::Response r, string url)
 
static cpr::Header as_cpr_header (http_headers hmap)
 
http_tree http_get (url u, http_headers headers)
 
http_tree http_head (url u, http_headers headers)
 
http_tree download (url from, url to, http_headers headers)
 
http_tree http_response_init ()
 
http_tree http_response_ref (http_tree r, http_label op)
 
void http_response_set (http_tree r, http_label op, http_tree t)
 

Variables

const charHTTP_USER_AGENT = "User-Agent"
 

Typedef Documentation

◆ http_tree

Definition at line 22 of file http.hpp.

◆ http_headers

Definition at line 37 of file http.hpp.

Enumeration Type Documentation

◆ http_label

Enumerator
STATUS_CODE 
TEXT 
URL 
ELAPSED 
HEADER 
PARAMETERS 
PAYLOAD 
MULTIPART 
TUPLE 
ROOT 

Definition at line 24 of file http.hpp.

24 : int {
25 STATUS_CODE= 1,
26 TEXT,
27 URL,
28 ELAPSED,
29 HEADER,
31 PAYLOAD,
33 TUPLE,
34 ROOT,
35};
@ PAYLOAD
Definition http.hpp:31
@ MULTIPART
Definition http.hpp:32
@ HEADER
Definition http.hpp:29
@ ELAPSED
Definition http.hpp:28
@ PARAMETERS
Definition http.hpp:30
@ STATUS_CODE
Definition http.hpp:25
@ TUPLE
Definition http.hpp:33

Function Documentation

◆ blackbox_tree()

template<typename T >
http_tree lolly::io::blackbox_tree ( int label,
T data )
inline

Definition at line 29 of file http.cpp.

29 {
30 http_tree ret= http_tree (label);
31 ret->data = close_box<T> (data);
32 return ret;
33}
The list class represents a linked list.
Definition list.hpp:48

◆ response_to_tree()

static http_tree lolly::io::response_to_tree ( cpr::Response r,
string url )
static

Definition at line 55 of file http.cpp.

55 {
58 ret, STATUS_CODE,
59 blackbox_tree<long> (http_label::STATUS_CODE, r.status_code));
61 ret, TEXT,
62 blackbox_tree<string> (http_label::TEXT, string (r.text.c_str ())));
64 blackbox_tree<string> (http_label::URL, string (url)));
65 http_response_set (ret, ELAPSED,
66 blackbox_tree<double> (http_label::ELAPSED, r.elapsed));
67
69 for (auto i= r.header.begin (); i != r.header.end (); i++) {
70 string key = locase_all (string (i->first.c_str ()));
71 string value= string (i->second.c_str ());
72 hmap (key) = value;
73 }
74 http_tree header=
75 blackbox_tree<hashmap<string, string>> (http_label::HEADER, hmap);
76 http_response_set (ret, HEADER, header);
77 return ret;
78}
string locase_all(string s)
Converts all uppercase characters in a string to lowercase.
Definition analyze.cpp:137
Definition url.hpp:37
void http_response_set(http_tree r, http_label op, http_tree t)
Definition http.hpp:60
http_tree http_response_init()
Definition http.hpp:42

◆ as_cpr_header()

static cpr::Header lolly::io::as_cpr_header ( http_headers hmap)
static

Definition at line 81 of file http.cpp.

81 {
84 while (it->busy ()) {
85 string key = it->next ();
86 header[std::string (c_string (key))]= c_string (hmap[key]);
87 }
88 return header;
89}
list(T item)
Construct a new list object with a single item.
Definition list.hpp:137
iterator< T > iterate(hashmap< T, U > h)
Generates an iterator for a container of type hashmap<T, U>.
Definition iterator.ipp:166

◆ http_get()

http_tree lolly::io::http_get ( url u,
http_headers headers )

Definition at line 92 of file http.cpp.

92 {
93 string u_str = as_string (u);
96 session.SetUrl (cpr::Url (u_cstr));
97 session.SetHeader (as_cpr_header (headers));
98 session.SetUserAgent (
99 cpr::UserAgent (std::string (c_string (headers[HTTP_USER_AGENT]))));
100 cpr::Response r= session.Get ();
101 return response_to_tree (r, u_str);
102}
static http_tree response_to_tree(cpr::Response r, string url)
Definition http.cpp:55
string as_string(int16_t i)
Definition string.cpp:272

◆ http_head()

http_tree lolly::io::http_head ( url u,
http_headers headers )

Definition at line 105 of file http.cpp.

105 {
106 string u_str = as_string (u);
109 session.SetUrl (cpr::Url (u_cstr));
110 session.SetHeader (as_cpr_header (headers));
111 session.SetUserAgent (
112 cpr::UserAgent (std::string (c_string (headers[HTTP_USER_AGENT]))));
113 cpr::Response r= session.Head ();
114 return response_to_tree (r, u_str);
115}

◆ download()

http_tree lolly::io::download ( url from,
url to,
http_headers headers )

Definition at line 118 of file http.cpp.

118 {
119 string from_str = as_string (from);
121 string to_str = as_string (to);
123
125 session.SetUrl (cpr::Url (from_cstr));
126 session.SetHeader (as_cpr_header (headers));
127 session.SetUserAgent (
128 cpr::UserAgent (std::string (c_string (headers[HTTP_USER_AGENT]))));
129 std::ofstream to_stream (to_cstr, std::ios::binary);
130 cpr::Response r= session.Download (to_stream);
131 return response_to_tree (r, from_str);
132}

◆ http_response_init()

http_tree lolly::io::http_response_init ( )
inline

Definition at line 42 of file http.hpp.

42 {
43 http_tree ret= http_tree (http_label::ROOT, 0);
44
45 ret << blackbox_tree<long> (http_label::STATUS_CODE, 404);
46 ret << blackbox_tree<string> (http_label::TEXT, string (""));
47 ret << blackbox_tree<string> (http_label::URL, string (""));
48 ret << blackbox_tree<double> (http_label::STATUS_CODE, 0.0);
51 return ret;
52}

◆ http_response_ref()

http_tree lolly::io::http_response_ref ( http_tree r,
http_label op )
inline

Definition at line 55 of file http.hpp.

55 {
56 return r[op - 1];
57}

◆ http_response_set()

void lolly::io::http_response_set ( http_tree r,
http_label op,
http_tree t )
inline

Definition at line 60 of file http.hpp.

60 {
61 r[op - 1]= t;
62}
blackbox t[13]

Variable Documentation

◆ HTTP_USER_AGENT

const char* lolly::io::HTTP_USER_AGENT = "User-Agent"

Definition at line 25 of file http.cpp.