Wed, 28 Dec 2016 12:23:51 +0100
using host header to select virtual server
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
4 | * Copyright 2008 Sun Microsystems, Inc. All rights reserved. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * THE BSD LICENSE |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * Redistribution and use in source and binary forms, with or without |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * modification, are permitted provided that the following conditions are met: |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * Redistributions of source code must retain the above copyright notice, this |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * list of conditions and the following disclaimer. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * Redistributions in binary form must reproduce the above copyright notice, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * this list of conditions and the following disclaimer in the documentation |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * and/or other materials provided with the distribution. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * Neither the name of the nor the names of its contributors may be |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * used to endorse or promote products derived from this software without |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * specific prior written permission. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
31 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
32 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
33 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
34 | #include <stdio.h> |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
35 | #include <stdlib.h> |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
36 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
37 | #include "http.h" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
38 | #include "protocol.h" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
39 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | #include "../util/pblock.h" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
41 | #include "../util/pool.h" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
42 | #include "../util/util.h" |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | static int http_etag = 1; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | /* --------------------------- http_format_etag --------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | NSAPI_PUBLIC void http_format_etag(Session *sn, Request *rq, char *etagp, int etaglen, off_t size, time_t mtime) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | * Heuristic for weak/strong validator: if the request was made within |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | * a second of the last-modified date, then we send a weak Etag. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | if (rq->req_start - mtime <= 1) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | /* Send a weak Etag */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | *etagp++ = 'W'; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | *etagp++ = '/'; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | etaglen -= 2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
61 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | /* |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | * Create an Etag out of the metadata (size, mtime) to obtain Etag |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | * uniqueness. |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
65 | */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
66 | util_snprintf(etagp, etaglen, "\"%x-%x\"", (int)size, (int)mtime); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | /* --------------------------- http_weaken_etag --------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | NSAPI_PUBLIC void http_weaken_etag(Session *sn, Request *rq) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | /* Replace any existing strong Etag with a weak Etag */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | pb_param *pp = pblock_findkey(pb_key_etag, rq->srvhdrs); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | if (pp) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | if (pp->value[0] != 'W' || pp->value[1] != '/') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | char *weak = (char *) pool_malloc(sn->pool, 2 + strlen(pp->value) + 1); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | weak[0] = 'W'; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | weak[1] = '/'; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | strcpy(weak + 2, pp->value); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | pool_free(sn->pool, pp->value); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | pp->value = weak; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | /* ------------------------------ match_etag ------------------------------ */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | NSAPI_PUBLIC int http_match_etag(const char *header, const char *etag, int strong) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | if (!etag) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | return 0; /* mismatch */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | if (header[0] == '*') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | return 1; /* match */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | if (etag[0] == 'W' && etag[1] == '/') { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | /* Weak Etags never match when using the strong validator */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | if (strong) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | return 0; /* mismatch */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | etag += 2; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | /* Look for Etag in header */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | const char *found = strstr(header, etag); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | if (!found) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | return 0; /* mismatch */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | /* Weak Etags never match when using the strong validator */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | if (strong && found >= header + 2 && found[-2] == 'W' && found[-1] == '/') |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | return 0; /* mismatch */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | return 1; /* match */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | /* ----------------------- http_check_preconditions ----------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | NSAPI_PUBLIC int http_check_preconditions(Session *sn, Request *rq, struct tm *mtm, const char *etag) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | char *header; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | /* If-modified-since */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | header = pblock_findkeyval(pb_key_if_modified_since, rq->headers); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | if (header) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | if (mtm && util_later_than(mtm, header)) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | protocol_status(sn, rq, PROTOCOL_NOT_MODIFIED, NULL); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | /* If-unmodified-since */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | header = pblock_findkeyval(pb_key_if_unmodified_since, rq->headers); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | if (header) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | if (mtm && !util_later_than(mtm, header)) { |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
141 | if(util_isdate(header)) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
142 | protocol_status(sn, rq, PROTOCOL_PRECONDITION_FAIL, NULL); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
143 | return REQ_ABORTED; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
144 | } |
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | /* If-none-match */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | header = pblock_findkeyval(pb_key_if_none_match, rq->headers); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | if (header) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | /* If the If-none-match header matches the current Etag... */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | if (ISMGET(rq) || ISMHEAD(rq)) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | if (http_match_etag(header, etag, PR_FALSE)) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | protocol_status(sn, rq, PROTOCOL_NOT_MODIFIED, NULL); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | if (http_match_etag(header, etag, PR_TRUE)) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | protocol_status(sn, rq, PROTOCOL_PRECONDITION_FAIL, NULL); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | /* If-match */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | header = pblock_findkeyval(pb_key_if_match, rq->headers); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | if (header) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | /* If the If-match header matches the current Etag... */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | if (!http_match_etag(header, etag, PR_TRUE)) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | protocol_status(sn, rq, PROTOCOL_PRECONDITION_FAIL, NULL); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | } |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
174 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
175 | /* If-range */ |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
176 | header = pblock_findkeyval(pb_key_if_range, rq->headers); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
177 | char *range = pblock_findkeyval(pb_key_range, rq->headers); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
178 | if (range && header) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
179 | int rmir = PR_FALSE; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
180 | if (util_isdate(header)) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
181 | if (mtm && !util_later_than(mtm, header)) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
182 | rmir = PR_TRUE; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
183 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
184 | } else { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
185 | if (!http_match_etag(header, etag, PR_TRUE)) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
186 | rmir = PR_TRUE; |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
187 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
188 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
189 | |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
190 | if(rmir) { |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
191 | pblock_removekey(pb_key_range, rq->headers); |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
192 | } |
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
102
diff
changeset
|
193 | } |
102
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | return REQ_PROCEED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | /* ---------------------------- http_set_finfo ---------------------------- */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | struct tm mtms; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | struct tm *mtm = system_gmtime(&mtime, &mtms); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | pb_param *pp; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | /* Insert Last-modified */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | if (mtm) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | pp = pblock_key_param_create(rq->srvhdrs, pb_key_last_modified, NULL, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | HTTP_DATE_LEN); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | if (!pp || !pp->value) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | strftime(pp->value, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | pblock_kpinsert(pb_key_last_modified, pp, rq->srvhdrs); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | /* Insert Content-length */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | const int content_length_size = 21; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | pp = pblock_key_param_create(rq->srvhdrs, pb_key_content_length, NULL, |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | content_length_size); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | if (!pp || !pp->value) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | snprintf(pp->value, content_length_size, "%lld", (long long)size); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | pblock_kpinsert(pb_key_content_length, pp, rq->srvhdrs); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | char *etag; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | if (http_etag) { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | /* Insert Etag */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | if (!pp || !pp->value) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | return REQ_ABORTED; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | etag = pp->value; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | } else { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
236 | etag = NULL; |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
237 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
239 | /* Check If-modified-since, etc. */ |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | return http_check_preconditions(sn, rq, mtm, etag); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
241 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo) |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
244 | { |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
245 | return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime); |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
246 | } |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
247 | |
136a76e293b5
added etag and conditional request implementation from Open Web Server
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | |
118
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
249 | /* ---------------------------- http_hdrs2env ----------------------------- */ |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
250 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
251 | NSAPI_PUBLIC char **http_hdrs2env(pblock *pb) |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
252 | { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
253 | char *t, *n, **env; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
254 | struct pb_entry *p; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
255 | pb_param *pp; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
256 | register int x, y, z; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
257 | int pos, ts, ln; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
258 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
259 | /* Find out how many there are. */ |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
260 | for(x = 0, y = 0; x < pb->hsize; x++) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
261 | p = pb->ht[x]; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
262 | while(p) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
263 | ++y; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
264 | p = p->next; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
265 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
266 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
267 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
268 | env = util_env_create(NULL, y, &pos); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
269 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
270 | ts = 1024; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
271 | t = (char *) MALLOC(ts); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
272 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
273 | for(x = 0; x < pb->hsize; x++) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
274 | p = pb->ht[x]; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
275 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
276 | while(p) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
277 | pp = p->param; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
278 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
279 | ln = strlen(pp->name) + 6; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
280 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
281 | if(ln >= ts) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
282 | ts = ln; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
283 | t = (char *) REALLOC(t, ts); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
284 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
285 | n = pp->name; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
286 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
287 | /* Skip authorization for CGI */ |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
288 | if(strcasecmp(n, "authorization")) { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
289 | if(strcasecmp(n, "content-type") && |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
290 | strcasecmp(n, "content-length")) |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
291 | { |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
292 | strncpy(t, "HTTP_", 5); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
293 | z = 5; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
294 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
295 | else |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
296 | z = 0; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
297 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
298 | for(y = 0; n[y]; ++y, ++z) |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
299 | t[z] = (n[y] == '-' ? '_' : toupper(n[y])); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
300 | t[z] = '\0'; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
301 | |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
302 | env[pos++] = util_env_str(t, pp->value); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
303 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
304 | p = p->next; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
305 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
306 | } |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
307 | env[pos] = NULL; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
308 | FREE(t); |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
309 | return env; |
38bf6dd8f4e7
adds minimal cgi implementation
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
104
diff
changeset
|
310 | } |