-
Notifications
You must be signed in to change notification settings - Fork 5
/
http.h
59 lines (44 loc) · 1.33 KB
/
http.h
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
#ifndef HTTP_H_
#define HTTP_H_
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
#include "dict.h"
#define BUFFERSIZE 1024
#define TRUE 1
#define FALSE 0
#define HTTP_SUCCESS 0
#define ERR_EOF -2
#define ERR_BROKEN_PIPE -3
#define ERR_CONNECTION_RESET -4
struct Host {
char *url;
int port;
unsigned int total_queries;
unsigned int total_time;
};
struct HttpRequest {
char *method;
char *resource;
struct dict *headers;
size_t content_length;
char *payload;
};
struct HttpResponse {
int status;
struct dict *headers;
size_t content_length;
char *payload;
};
ssize_t send_all(int socket, const void *buffer, size_t length, int flags);
ssize_t read_all(int socket, void *buffer, size_t length);
int http_create_inet_socket(const char *port);
int http_open_connection(const char *url, int port);
int http_receive_request(int sockfd, struct HttpRequest **received_request);
int http_receive_response(int sockfd, struct HttpResponse **received_response);
struct HttpResponse *executeRequest(struct Host *host, struct HttpRequest *request);
int http_send_request(int sockfd, struct HttpRequest *request);
int http_send_response(int sockfd, struct HttpResponse *response);
void HttpRequest_free(struct HttpRequest *request);
void HttpResponse_free(struct HttpResponse *response);
#endif