-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget.c
executable file
·43 lines (34 loc) · 1.01 KB
/
get.c
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
/*
* ****************************************************************************
*
* PROJECT: Maze
*
* AUTHOR: Brian Mayer [email protected]
*
* NOTES: This is the function that sends the file requested in a
* response, it takes two arguments: the client's connection and
* the file requested in the GET message.
*
* ****************************************************************************
*/
#include "get.h"
short send_get(short conn, struct request req)
{
/* Verify the connection and request version */
if(req.conn == NULL && req.vers > 1) {
req.conn = "Keep-Alive";
}
/* Client identification */
req.user = "Maze/" VERSION;
/* Accept encoding */
req.cenc = "*/*";
/* Create the head */
char request[req_header_len(req)];
create_req_header(req, request);
printf("header len: %d\n", strlen(request));
printf("request:\n%s\n", request);
/* Send the request */
write(conn, request, strlen(request));
puts("\tGET request sent.");
return 0;
}