Mon, 10 Jul 2023 18:52:28 +0200
add WS_CFLAGS to admin makefile
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
1 | /* |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
3 | * |
44
3da1f7b6847f
added some error messages
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
38
diff
changeset
|
4 | * Copyright 2013 Olaf Wintermann. All rights reserved. |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
5 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
8 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
11 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
15 | * |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
27 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
28 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
29 | #include "protocol.h" |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
30 | |
121
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
31 | #include "session.h" |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
32 | #include "httplistener.h" |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
33 | #include "request.h" |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
34 | |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
35 | #include "../util/pblock.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
36 | #include "../util/pool.h" |
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
37 | #include "../util/io.h" |
103
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
38 | #include "../util/util.h" |
14
b8bf95b39952
New source folder layout
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
11
diff
changeset
|
39 | #include "../util/strbuf.h" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
40 | |
121
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
41 | #define HTTP_SCHEME "http" |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
42 | #define HTTPS_SCHEME "https" |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
43 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
44 | void protocol_status(Session *sn, Request *rq, int n, const char *m) { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
45 | rq->status_num = n; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
46 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
47 | const char *msg = m ? m : protocol_status_message(n); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
48 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
49 | pb_param *pp = pblock_removekey(pb_key_status, rq->srvhdrs); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
50 | if (pp != NULL) { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
51 | param_free(pp); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
52 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
53 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
54 | pp = pblock_key_param_create(rq->srvhdrs, pb_key_status, msg, strlen(msg)); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
55 | pblock_kpinsert(pb_key_status, pp, rq->srvhdrs); |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
56 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
57 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
58 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
59 | /* |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
60 | * http_status_message from Open Webserver (frame/http.cpp) |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
251
diff
changeset
|
61 | * TODO: replace, use cxmutstr |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
62 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
63 | NSAPI_PUBLIC const char * protocol_status_message (int code) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
64 | { |
87
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
65 | WS_ASSERT(code > 0); |
bdec069d2239
fixed pathcheck behavior
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
82
diff
changeset
|
66 | |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
67 | const char *r; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
68 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
69 | switch (code) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
70 | { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
71 | case PROTOCOL_CONTINUE : // 100 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
72 | r = "Continue"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
73 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
74 | case PROTOCOL_SWITCHING: //101 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
75 | r = "Switching Protocols"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
76 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
77 | case PROTOCOL_OK: // 200 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
78 | r = "OK"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
79 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
80 | case PROTOCOL_CREATED: // 201 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
81 | r = "Created"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
82 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
83 | case PROTOCOL_ACCEPTED: // 202 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
84 | r = "Accepted"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
85 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
86 | case PROTOCOL_NONAUTHORITATIVE: // 203 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
87 | r = "Non-Authoritative Information"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
88 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
89 | case PROTOCOL_NO_CONTENT: //204 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
90 | /* There is another define to PROTOCOL_NO_RESPONSE for 204 in nsapi.h |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
91 | The spec maps this to No Content. |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
92 | Hence cahnging this to No Content |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
93 | */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
94 | r = "No Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
95 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
96 | case PROTOCOL_RESET_CONTENT: // 205 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
97 | r = "Reset Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
98 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
99 | case PROTOCOL_PARTIAL_CONTENT: // 206 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
100 | r = "Partial Content"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
101 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
102 | case PROTOCOL_MULTI_STATUS: // 207 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
103 | r = "Multi Status"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
104 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
105 | case PROTOCOL_MULTIPLE_CHOICES: // 300 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
106 | r = "Multiple Choices"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
107 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
108 | case PROTOCOL_MOVED_PERMANENTLY: // 301 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
109 | r = "Moved Permanently"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
110 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
111 | case PROTOCOL_REDIRECT: // 302 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
112 | r = "Moved Temporarily"; /* The spec actually says "Found" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
113 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
114 | case PROTOCOL_SEE_OTHER: // 303 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
115 | r = "See Other"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
116 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
117 | case PROTOCOL_NOT_MODIFIED: // 304 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
118 | r = "Use local copy"; /* The spec actually says "Not Modified" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
119 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
120 | case PROTOCOL_USE_PROXY: // 305 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
121 | r = "Use Proxy"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
122 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
123 | case PROTOCOL_TEMPORARY_REDIRECT: // 307 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
124 | r = "Temporary Redirect"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
125 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
126 | case PROTOCOL_BAD_REQUEST: // 400 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
127 | r = "Bad request"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
128 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
129 | case PROTOCOL_UNAUTHORIZED: // 401 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
130 | r = "Unauthorized"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
131 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
132 | case PROTOCOL_PAYMENT_REQUIRED: // 402 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
133 | r = "Payment Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
134 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
135 | case PROTOCOL_FORBIDDEN: // 403 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
136 | r = "Forbidden"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
137 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
138 | case PROTOCOL_NOT_FOUND: // 404 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
139 | r = "Not found"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
140 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
141 | case PROTOCOL_METHOD_NOT_ALLOWED: // 405 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
142 | r = "Method Not Allowed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
143 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
144 | case PROTOCOL_NOT_ACCEPTABLE: // 406 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
145 | r = "Not Acceptable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
146 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
147 | case PROTOCOL_PROXY_UNAUTHORIZED: // 407 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
148 | r = "Proxy Authentication Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
149 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
150 | case PROTOCOL_REQUEST_TIMEOUT: // 408 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
151 | r = "Request Timeout"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
152 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
153 | case PROTOCOL_CONFLICT: // 409 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
154 | r = "Conflict"; /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
155 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
156 | case PROTOCOL_GONE: // 410 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
157 | r = "Gone"; /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
158 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
159 | case PROTOCOL_LENGTH_REQUIRED: // 411 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
160 | r = "Length Required"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
161 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
162 | case PROTOCOL_PRECONDITION_FAIL: // 412 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
163 | r = "Precondition Failed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
164 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
165 | case PROTOCOL_ENTITY_TOO_LARGE: // 413 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
166 | r = "Request Entity Too Large"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
167 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
168 | case PROTOCOL_URI_TOO_LARGE: // 414 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
169 | r = "Request-URI Too Large"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
170 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
171 | case PROTOCOL_UNSUPPORTED_MEDIA_TYPE: // 415 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
172 | r = "Unsupported Media Type"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
173 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
174 | case PROTOCOL_REQUESTED_RANGE_NOT_SATISFIABLE: // 416 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
175 | r = "Requested range not satisfiable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
176 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
177 | case PROTOCOL_EXPECTATION_FAILED: // 417 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
178 | r = "Expectation Failed"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
179 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
180 | case PROTOCOL_LOCKED: // 423 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
181 | r = "Locked"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
182 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
183 | case PROTOCOL_FAILED_DEPENDENCY: // 424 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
184 | r = "Failed Dependency"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
185 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
186 | case PROTOCOL_SERVER_ERROR: // 500 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
187 | r = "Server Error"; /* The spec actually says "Internal Server Error" */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
188 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
189 | case PROTOCOL_NOT_IMPLEMENTED: // 501 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
190 | r = "Not Implemented"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
191 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
192 | case PROTOCOL_BAD_GATEWAY: // 502 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
193 | r = "Bad Gateway"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
194 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
195 | case PROTOCOL_SERVICE_UNAVAILABLE: // 503 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
196 | r = "Service Unavailable"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
197 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
198 | case PROTOCOL_GATEWAY_TIMEOUT: // 504 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
199 | r = "Gateway Timeout"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
200 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
201 | case PROTOCOL_VERSION_NOT_SUPPORTED: // 505 /* HTTP/1.1 */ |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
202 | r = "HTTP Version Not Supported"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
203 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
204 | case PROTOCOL_INSUFFICIENT_STORAGE: // 507 |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
205 | r = "Insufficient Storage"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
206 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
207 | default: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
208 | switch (code / 100) |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
209 | { |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
210 | case 1: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
211 | r = "Information"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
212 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
213 | case 2: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
214 | r = "Success"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
215 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
216 | case 3: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
217 | r = "Redirect"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
218 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
219 | case 4: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
220 | r = "Client error"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
221 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
222 | case 5: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
223 | r = "Server error"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
224 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
225 | default: |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
226 | r = "Unknown reason"; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
227 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
228 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
229 | break; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
230 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
231 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
232 | return r; |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
233 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
234 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
235 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
236 | void add_http_status_line(CxBuffer *out, pool_handle_t *pool, Request *rq) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
237 | cxBufferWrite("HTTP/1.1 ", 1, 9, out); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
238 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
239 | char status_code_str[8]; |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
240 | int sc_len = snprintf(status_code_str, 8, "%d ", rq->status_num); |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
241 | cxBufferWrite(status_code_str, 1, sc_len, out); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
242 | |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
243 | char *scmsg = pblock_findkeyval(pb_key_status, rq->srvhdrs); |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
244 | if(scmsg == NULL) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
245 | scmsg = "OK"; |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
246 | } |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
247 | cxBufferWrite(scmsg, 1, strlen(scmsg), out); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
248 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
249 | cxBufferWrite("\r\n", 1, 2, out); |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
250 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
251 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
252 | void add_http_response_header(CxBuffer *out, Request *rq) { |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
253 | pblock *h = rq->srvhdrs; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
254 | pb_entry *p; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
255 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
256 | for(int i=0;i<h->hsize;i++) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
257 | p = h->ht[i]; |
45
a24aa388f02f
added access log
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
44
diff
changeset
|
258 | while(p != NULL) { |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
259 | /* from http.cpp */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
260 | const pb_key *key = PARAM_KEY(p->param); |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
261 | if (key == pb_key_status || key == pb_key_server || key == pb_key_date) { |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
262 | /* Skip internal Status:, Server:, and Date: information */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
263 | p = p->next; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
264 | continue; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
265 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
266 | /* end http.cpp */ |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
267 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
268 | char *name = p->param->name; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
269 | char *value = p->param->value; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
270 | |
77 | 271 | // make first char of name uppercase |
272 | size_t name_len = strlen(name); | |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
273 | if(name[0] > 90) { |
77 | 274 | /* |
275 | * make first char uppercase and write the remaining chars | |
276 | * unmodified to the buffer | |
277 | */ | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
278 | cxBufferPut(out, name[0]-32); |
77 | 279 | if(name_len > 1) { |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
280 | cxBufferWrite(name+1, 1, name_len-1, out); |
77 | 281 | } |
282 | } else { | |
283 | // first char is already uppercase so just write the name | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
284 | cxBufferWrite(name, 1, name_len, out); |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
285 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
286 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
287 | cxBufferWrite(": ", 1, 2, out); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
288 | cxBufferWrite(value, 1, strlen(value), out); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
289 | cxBufferWrite("\r\n", 1, 2, out); |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
290 | |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
291 | p = p->next; |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
292 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
293 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
294 | } |
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
295 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
296 | struct HttpResponseWriter { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
297 | Session *sn; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
298 | Request *rq; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
299 | CxBuffer buf; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
300 | }; |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
301 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
302 | HttpResponseWriter *http_create_response(Session *sn, Request *rq) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
303 | HttpResponseWriter *writer = pool_malloc(sn->pool, sizeof(HttpResponseWriter)); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
304 | if(!writer) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
305 | return NULL; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
306 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
307 | if(cxBufferInit(&writer->buf, NULL, 512, pool_allocator(sn->pool), CX_BUFFER_AUTO_EXTEND|CX_BUFFER_FREE_CONTENTS)) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
308 | pool_free(sn->pool, writer); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
309 | return NULL; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
310 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
311 | writer->sn = sn; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
312 | writer->rq = rq; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
313 | |
23
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
314 | if(rq->status_num == -1) { |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
315 | protocol_status(sn, rq, 200, "OK"); |
a2c8fc23c90e
Added basic authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
21
diff
changeset
|
316 | } |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
317 | |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
318 | // add the http status line to the output buffer |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
319 | add_http_status_line(&writer->buf, sn->pool, rq); |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
320 | |
103
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
321 | // add date header |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
322 | struct tm mtms; |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
323 | struct tm *mtm = system_gmtime(&rq->req_start, &mtms); |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
324 | char date[HTTP_DATE_LEN + 1]; |
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
325 | strftime(date, HTTP_DATE_LEN, HTTP_DATE_FMT, mtm); |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
326 | cxBufferWrite("Date: ", 1, 6, &writer->buf); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
327 | cxBufferWrite(date, 1, strlen(date), &writer->buf); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
328 | cxBufferWrite("\r\n", 1, 2, &writer->buf); |
103
d3b514e2ddbd
added date header to response
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
101
diff
changeset
|
329 | |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
330 | // add server header |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
331 | cxBufferWrite("Server: webserver\r\n", 1, 19, &writer->buf); |
104
a8acbb12f27c
implemented range requests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
103
diff
changeset
|
332 | |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
333 | // check content length ans transfer encoding |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
334 | char *ctlen = pblock_findkeyval(pb_key_content_length, rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
335 | char *enc = pblock_findkeyval(pb_key_transfer_encoding, rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
336 | if(ctlen && enc) { |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
337 | pblock_removekey(pb_key_transfer_encoding, rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
338 | } |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
339 | if(!ctlen) { |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
340 | // set transfer-encoding header |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
341 | if(!enc) { |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
342 | pblock_kvinsert( |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
343 | pb_key_transfer_encoding, |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
344 | "chunked", |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
345 | 7, |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
346 | rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
347 | } else if(strcmp(enc, "chunked")) { |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
348 | pblock_removekey(pb_key_transfer_encoding, rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
349 | pblock_kvinsert( |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
350 | pb_key_transfer_encoding, |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
351 | "chunked", |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
352 | 7, |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
353 | rq->srvhdrs); |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
354 | } |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
355 | |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
356 | // set stream property |
251
f727a21497bb
add basic PUT implementation and tests
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
235
diff
changeset
|
357 | HttpStream *stream = (HttpStream*)sn->csd; // TODO: make this typesafe |
66
74babc0082b7
added authentication cache
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
65
diff
changeset
|
358 | stream->chunked_enc = 1; |
80
0de4a90979e1
fixed chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
78
diff
changeset
|
359 | rq->rq_attr.chunked = 1; |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
360 | } |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
361 | |
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
362 | // add header from rq->srvhdrs |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
363 | add_http_response_header(&writer->buf, rq); |
48
37a512d7b8f6
fixed some memory leaks
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
45
diff
changeset
|
364 | |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
365 | // add connection header |
101
7fbcdbad0baa
added support for absolute URIs and improved keep alive
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
87
diff
changeset
|
366 | if(rq->rq_attr.keep_alive) { |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
367 | cxBufferWrite("Connection: keep-alive\r\n", 1, 24, &writer->buf); |
78
3578977d29a3
added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
368 | pblock_kvinsert(pb_key_connection, "keep-alive", 10, rq->srvhdrs); |
3578977d29a3
added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
369 | } else { |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
370 | cxBufferWrite("Connection: close\r\n", 1, 19, &writer->buf); |
78
3578977d29a3
added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
371 | pblock_kvinsert(pb_key_connection, "close", 5, rq->srvhdrs); |
3578977d29a3
added keep-alive support
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
77
diff
changeset
|
372 | } |
7
3c2ed7a7a5fd
request and response header now used
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
4
diff
changeset
|
373 | |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
374 | // response header end |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
375 | cxBufferWrite("\r\n", 1, 2,& writer->buf); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
376 | |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
377 | // reset pos (required for http_start_response_async) |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
378 | writer->buf.pos = 0; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
379 | |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
380 | return writer; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
381 | } |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
382 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
383 | int http_send_response(HttpResponseWriter *writer) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
384 | Connection *conn = ((NSAPISession*)writer->sn)->connection; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
385 | CxBuffer *buf = &writer->buf; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
386 | |
65
14722c5f8856
added chunked transfer encoding
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
48
diff
changeset
|
387 | // flush buffer to the socket |
433
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
388 | int ret = 0; |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
389 | while(buf->pos < buf->size) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
390 | int w = conn->write(conn, buf->space + buf->pos, buf->size - buf->pos); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
391 | if(w <= 0) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
392 | if(conn->ssl) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
393 | if(conn->ssl_error == SSL_ERROR_WANT_WRITE) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
394 | return 1; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
395 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
396 | } else { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
397 | if(errno == EWOULDBLOCK) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
398 | return 1; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
399 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
400 | } |
433
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
401 | ret = -1; |
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
402 | break; |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
403 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
404 | buf->pos += w; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
405 | } |
141 | 406 | |
433
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
407 | if(ret == 0) { |
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
408 | writer->rq->senthdrs = 1; |
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
409 | } |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
410 | |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
411 | cxBufferDestroy(buf); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
412 | pool_free(writer->sn->pool, writer); |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
413 | |
433
39fe86ae4db0
use non-blocking IO for pipes and socket in send_cgi
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
432
diff
changeset
|
414 | return ret; |
4
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
415 | } |
998844b5ed25
Added some protocol functions
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
diff
changeset
|
416 | |
432
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
417 | |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
418 | int http_start_response(Session *sn, Request *rq) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
419 | HttpResponseWriter *writer = http_create_response(sn, rq); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
420 | if(!writer) { |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
421 | return 1; |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
422 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
423 | |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
424 | return http_send_response(writer); |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
425 | } |
7c9137f9e7f9
add http_send_response function that is usable for non-blocking IO
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
415
diff
changeset
|
426 | |
235
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
427 | int http_send_continue(Session *sn) { |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
428 | NSAPISession *s = (NSAPISession*)sn; |
415
d938228c382e
switch from ucx 2 to 3
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
251
diff
changeset
|
429 | cxstring msg = CX_STR("HTTP/1.1 100 Continue\r\n\r\n"); |
235
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
430 | int w = s->connection->write(s->connection, msg.ptr, msg.length); |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
431 | if(w != msg.length) { |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
432 | return 1; |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
433 | } |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
434 | return 0; |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
435 | } |
4990147c58d0
add handler for http expect header
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
141
diff
changeset
|
436 | |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
437 | int request_header(char *name, char **value, Session *sn, Request *rq) { |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
438 | const pb_key *key = pblock_key(name); |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
439 | pb_param *pp = pblock_findkey(key, rq->headers); |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
440 | if(pp != NULL) { |
21
627b09ee74e4
New configuration loader
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
14
diff
changeset
|
441 | *value = pp->value; |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
442 | return REQ_PROCEED; |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
443 | } else { |
38
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
444 | //return REQ_ABORTED; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
445 | *value = NULL; |
d07810b02147
added ldap authentication
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
23
diff
changeset
|
446 | return REQ_NOACTION; |
9
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
447 | } |
30e51941a673
Added mod_jk dependencies
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
8
diff
changeset
|
448 | } |
82
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
449 | |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
450 | char *http_uri2url(const char *prefix, const char *suffix) { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
451 | // TODO: implement |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
452 | return NULL; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
453 | } |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
454 | |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
455 | char *http_uri2url_dynamic(const char *prefix, const char *suffix, |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
456 | Session *sn, Request *rq) |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
457 | { |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
458 | // TODO: implement |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
459 | return NULL; |
740cfd9dd443
added some nsapi stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
80
diff
changeset
|
460 | } |
121
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
461 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
462 | void http_get_scheme_host_port( |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
463 | Session *sn, |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
464 | Request *rq, |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
465 | char **scheme, |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
466 | char **host, |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
467 | uint16_t *port) |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
468 | { |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
469 | Connection *con = ((NSAPISession*)sn)->connection; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
470 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
471 | if(con->ssl) { |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
472 | *scheme = HTTPS_SCHEME; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
473 | } else { |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
474 | *scheme = HTTP_SCHEME; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
475 | } |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
476 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
477 | NSAPIRequest *request = (NSAPIRequest*)rq; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
478 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
479 | if(request->host) { |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
480 | *host = request->host; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
481 | } else { |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
482 | *host = "localhost"; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
483 | } |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
484 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
485 | *port = request->port; |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
486 | |
a881dc866e23
adds more CGI stuff
Olaf Wintermann <olaf.wintermann@gmail.com>
parents:
110
diff
changeset
|
487 | } |