-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrequests.hpp
81 lines (56 loc) · 2.01 KB
/
requests.hpp
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
#ifndef _REQUESTS_
#define _REQEUSTS_
#include <stdlib.h> /* exit, atoi, malloc, free */
#include <stdio.h>
#include <unistd.h> /* read, write, close */
#include <string.h> /* memcpy, memset */
#include <sys/socket.h> /* socket, connect */
#include <netinet/in.h> /* struct sockaddr_in, struct sockaddr */
#include <netdb.h> /* struct hostent, gethostbyname */
#include <arpa/inet.h>
#include <string>
#include "helpers.hpp"
using namespace std;
string compute_get_request(string host, string url, string jwt_token, string cookie) {
string message = "";
message += "GET " + url + " HTTP/1.1\r\n";
message += "Host: " + host + "\r\n";
if (jwt_token.compare("") != 0) {
message += "Authorization: Bearer " + jwt_token + "\r\n";
}
if (cookie.compare("") != 0) {
message += "Cookie: " + cookie + "\r\n";
}
message += "\r\n";
return message;
}
string compute_post_request(string host, string url, string content_type, string body_data, int body_size, string jwt_token, string cookie) {
string message = "";
message += "POST " + url + " HTTP/1.1\r\n";
message += "Host: " + host + "\r\n";
message += "Content-Type: " + content_type + "\r\n";
message += "Content-Length: " + to_string(body_size) + "\r\n";
if (cookie.compare("") != 0) {
message += "Cookie: " + cookie + "\r\n";
}
if (jwt_token.compare("") != 0) {
message += "Authorization: Bearer " + jwt_token + "\r\n";
}
message += "\r\n";
message += body_data;
return message;
}
string compute_delete_request(string host, string url, string jwt_token, string cookie) {
string message = "";
message += "DELETE " + url + " HTTP/1.1\r\n";
message += "Host: " + host + "\r\n";
if (jwt_token.compare("") != 0) {
message += "Authorization: Bearer " + jwt_token + "\r\n";
}
if (cookie.compare("") != 0) {
message += "Cookie: " + cookie + "\r\n";
}
message += "\r\n";
return message;
}
#endif