-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeserializeResponse.c
More file actions
45 lines (40 loc) · 1.78 KB
/
Copy pathdeserializeResponse.c
File metadata and controls
45 lines (40 loc) · 1.78 KB
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
//
// Created by aidankeefe on 5/21/26.
//
#include "../include/deserializeResponse.h"
bool https_responseAddStatus(struct https_response* response, u64 status, struct aid_string statusReason) {
response->status = status;
response->statusReason = statusReason;
return true;
}
bool https_responseAddHeader(struct https_response* response, struct aid_string* headerText) {
aid_push(&response->headers, headerText, STRING);
return true;
}
bool https_responseAddBody(struct https_response* response, struct aid_string body) {
response->body = body;
return true;
}
struct aid_string https_responseDeserialize(struct https_response* response) {
struct aid_string responseString = (struct aid_string){.options = AID_STR_AUTO_RESIZE};\
aid_str_append_string(&responseString, &STR_LIT("HTTP/1.1 "));
aid_str_append_int(&responseString, response->status);
aid_str_append_char(&responseString, ' ');
aid_str_append_string(&responseString, &response->statusReason);
aid_str_append_char(&responseString, '\r');
aid_str_append_char(&responseString, '\n');
aid_str_append_string(&responseString, &STR_LIT("Content-Length: "));
aid_str_append_int(&responseString, response->body.length);
aid_str_append_char(&responseString, '\r');
aid_str_append_char(&responseString, '\n');
for (aid_LLNode *node = response->headers.head; node != nullptr; node = node->next) {
aid_str_append_string(&responseString, node->STRING);
aid_str_append_char(&responseString, '\r');
aid_str_append_char(&responseString, '\n');
}
aid_str_append_char(&responseString, '\r');
aid_str_append_char(&responseString, '\n');
aid_str_append_string(&responseString, &response->body);
aid_free_LL(&response->headers);
return responseString;
}