5MP Motion Camera JPEG Image and Movie Catcher  1.1.1.1
A CGI interface to capture and display pictures and movies using OpenCV.
http_io.hpp
Go to the documentation of this file.
1 //
2 // Created by patrick on 4/9/20.
3 //
4 
5 #ifndef HTTP_IO_HPP
6 #define HTTP_IO_HPP
7 #include <iostream>
8 #include <string>
9 #include <map>
10 #include <iterator>
11 #include <vector>
12 #include <cctype>
13 #include <algorithm>
14 #include <regex>
15 #include "string_util.hpp"
16 
17 using namespace std;
18 
19 class http_io {
20  const string content_type_parser = R"END(^(.*?);\s(.*)$)END";
21  regex content_type_regex{content_type_parser, std::regex_constants::optimize};
22 
23 public:
24  map<string, string> env;
25  map<string, string> header; // HTTP response (output) headers.
26  map<int, string> http_status{
27  {100, "Continue"},
28  {101, "Switching Protocols"},
29  {200, "OK"},
30  {201, "Created"},
31  {202, "Accepted"},
32  {203, "Non-Authoritative Information"},
33  {204, "No Content"},
34  {205, "Reset Content"},
35  {206, "Partial Content"},
36  {300, "Multiple Choices"},
37  {301, "Moved Permanently"},
38  {302, "Found"},
39  {303, "See Other"},
40  {304, "Not Modified"},
41  {305, "Use Proxy"},
42  {307, "Temporary Redirect"},
43  {400, "Bad Request"},
44  {401, "Unauthorized"},
45  {402, "Payment Required"},
46  {403, "Forbidden"},
47  {404, "Not Found"},
48  {405, "Method Not Allowed"},
49  {406, "Not Acceptable"},
50  {407, "Proxy Authentication Required"},
51  {408, "Request Time-out"},
52  {409, "Conflict"},
53  {410, "Gone"},
54  {411, "Length Required"},
55  {412, "Precondition Failed"},
56  {413, "Request Entity Too Large"},
57  {414, "Request-URI Too Large"},
58  {415, "Unsupported Media Type"},
59  {416, "Requested range not satisfiable"},
60  {417, "Expectation Failed"},
61  {500, "Internal Server Error"},
62  {501, "Not Implemented"},
63  {502, "Bad Gateway"},
64  {503, "Service Unavailable"},
65  {504, "Gateway Time-out"},
66  {505, "HTTP Version not supported"}
67  };
68  bool https{false};
69  string locale;
70 
71  void get_env(char *env_p[]);
72  explicit http_io();
73  void print_env(ostream &o_stream);
74  void respond(ostringstream &o_stream,
75  int status = 200,
76  string mime = "text/plain",
77  string charset = "utf-8");
79 };
80 
81 
82 #endif //HTTP_IO_HPP
map< string, string > env
Definition: http_io.hpp:24
map< string, string > header
Definition: http_io.hpp:25
Definition: http_io.hpp:19
Definition: string_util.hpp:31
string_util su
Definition: http_io.hpp:78
string locale
Definition: http_io.hpp:69