-
Notifications
You must be signed in to change notification settings - Fork 0
/
skeleton.c
68 lines (58 loc) · 1.77 KB
/
skeleton.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
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
// Handle an incoming HTTP request. (Return a response).
void http_handle(char *raw)
{
struct req request;
char *data;
request = get_request(raw);
data = http_get_data(request);
http_send_response(data);
{
// Send data to the client, as an HTTP 200 response.
void http_respond(data)
{
// XXX data contains body + headers
// XXX just need to do ksocket_send()
}
// Send a HTTP request to a remote server. Behaves like ruby equiv
http_response http_get(request, mod_date)
{
}
// Get the (possibly cached) data corresponding to the given tag.
data http_get_data(request)
{
if (cache_contains(request)) { // the request has been cached previously
if (mod_date = cache_get_mod_date(request)) { // the request is cached w/ a last modified date stored
response = http_get(request, mod_date);
if (response) {
data = cache_write(request, response);
} else {
data = cache_read(request);
}
} else if (cache_is_expired(request)) {
response = http_get(request);
data = cache_write(request, response);
} else {
data = cache_read(request);
}
} else { // the request has never been cached
response = http_get(request);
data = cache_write(request, response);
}
return data;
}
// Update the cache with the given request/response combo (file-based?)
data cache_write(request, response)
{
// XXX
// XXX cache entries need: 1)data, 2)expiry date, 3) last modified datecache_update(request, response);
}
// Read from the cache. (File-based)
data cache_read(request)
{
// XXX munge the request into index and read from cache
}
// Is the expiry past time.now?
boolean cache_is_expired(request)
{
// XXX
}