This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
http.hh
107 lines (83 loc) · 1.81 KB
/
http.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* HTTP/1.0 for streams sockets
* Copyright(c) 2003-2018 of wave++ (Yuri D'Elia)
* Distributed under GNU LGPL without ANY warranty.
*/
#ifndef http_hh
#define http_hh
// local headers
#include "socket.hh"
// system headers
#include <vector>
#include <string>
// protocol constants
namespace Http
{
namespace Proto
{
// parameters
const extern char* proto;
const extern char* port;
const extern char* protoTy;
const extern char* version;
const size_t hdrLen = 1024;
const extern char* endl;
const size_t endlSz = 2;
// requests
const extern char* get;
const extern char* authorization;
const extern char* basic;
// answers
const int ok = 200;
const int moved = 301;
const int found = 302;
const int other = 303;
// headers we parse
const extern char* location;
}
// some useful typedefs
typedef std::vector<std::string> Header;
// HTTP transport reply
struct Reply
{
Reply(Header* headers = NULL)
: headers(headers)
{}
// necessary data
std::string proto;
int code;
std::string description;
// optional headers
Header* headers;
};
struct Auth
{
std::string user;
std::string pass;
std::string
basicHeader() const;
};
// interface
class Http
{
char* host;
char* port;
timeval* timeout;
// http functions
void
readReply(Socket& s, Reply& reply);
protected:
// generic operations
Socket*
gen(const char* act, const char* path, Reply& reply,
const Header* headers = NULL);
public:
// de/constructors
Http(const char* host, const char* port = NULL, const timeval* timeout = NULL);
~Http();
// basic functionality
Socket*
get(const char* file, Reply& reply, const Header* headers = NULL);
};
}
#endif