Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 227 lines (182 sloc) 5.911 kb
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
3 /* Cherokee
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
4 *
5 * Authors:
6 * Alvaro Lopez Ortega <alvaro@alobbs.com>
7 *
920e20b @alobbs Happy new year!
alobbs authored
8 * Copyright (C) 2001-2011 Alvaro Lopez Ortega
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
2c39092 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@2660 5dc97367-9…
alobbs authored
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * 02110-1301, USA.
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
23 */
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
24
25 #include "common-internal.h"
26 #include "request.h"
27
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
28 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
29 cherokee_request_header_init (cherokee_request_header_t *request)
30 {
31 ret_t ret;
32
33 /* Init the node list information
34 */
337832a @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@1375 5dc97367-9…
alobbs authored
35 INIT_LIST_HEAD (LIST(&request->list_node));
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
36
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
37 /* Set default values
38 */
39 request->method = http_get;
40 request->version = http_version_11;
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
41 request->auth = http_auth_nothing;
67339f1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@921 5dc97367-97…
alobbs authored
42 request->proxy = false;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
43 request->keepalive = true;
44 request->pipeline = 1;
45 request->post_len = 0;
46
47 ret = cherokee_url_init (&request->url);
48 if (unlikely(ret < ret_ok)) return ret;
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
49
50 cherokee_buffer_init (&request->extra_headers);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
51 cherokee_buffer_init (&request->user);
52 cherokee_buffer_init (&request->password);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
53
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
54 return ret_ok;
55 }
56
57
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
58 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
59 cherokee_request_header_mrproper (cherokee_request_header_t *request)
60 {
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
61 cherokee_buffer_mrproper (&request->user);
62 cherokee_buffer_mrproper (&request->password);
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
63 cherokee_buffer_mrproper (&request->extra_headers);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
64
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
65 cherokee_url_mrproper (&request->url);
66 return ret_ok;
67 }
68
69
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
70 ret_t
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
71 cherokee_request_header_clean (cherokee_request_header_t *request)
72 {
73 request->method = http_get;
74 request->version = http_version_11;
75 request->keepalive = true;
76 request->pipeline = 1;
77 request->post_len = 0;
78
79 cherokee_url_clean (&request->url);
80
81 return ret_ok;
82 }
83
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
84 ret_t
67339f1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@921 5dc97367-97…
alobbs authored
85 cherokee_request_header_uses_proxy (cherokee_request_header_t *request, cherokee_boolean_t proxy)
86 {
87 request->proxy = proxy;
88 return ret_ok;
89 }
90
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
91
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
92 ret_t
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
93 cherokee_request_header_parse_string (cherokee_request_header_t *request, cherokee_buffer_t *url_string)
94 {
95 return cherokee_url_parse (&request->url, url_string, &request->user, &request->password);
96 }
97
98
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
99 ret_t
3c2b494 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97…
alobbs authored
100 cherokee_request_header_build_string (cherokee_request_header_t *request, cherokee_buffer_t *buf, cherokee_buffer_t *tmp1, cherokee_buffer_t *tmp2)
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
101 {
67339f1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@921 5dc97367-97…
alobbs authored
102 ret_t ret;
103 const char *ptr;
104 cuint_t len;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
105 cherokee_url_t *url = REQUEST_URL(request);
106
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
107 /* 200 bytes should be enough for a small header
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
108 */
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
109 cherokee_buffer_ensure_size (buf, 200);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
110
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
111 /* Add main request line:
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
112 * GET /dir/object HTTP/1.1
113 */
67339f1 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@921 5dc97367-97…
alobbs authored
114 ret = cherokee_http_method_to_string (request->method, &ptr, &len);
115 if (ret != ret_ok) return ret;
116
117 ret = cherokee_buffer_add (buf, ptr, len);
118 if (ret != ret_ok) return ret;
119
120 cherokee_buffer_add_str (buf, " ");
121
122 /* Check if the requests goes through a proxy
123 */
124 if (request->proxy) {
125 cherokee_buffer_add_str (buf, "http://");
126 cherokee_buffer_add_buffer (buf, URL_HOST(url));
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
127 }
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
128
129 cherokee_buffer_add_buffer (buf, URL_REQUEST(url));
130
131 switch (REQUEST_VERSION(request)) {
132 case http_version_11:
6363e73 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@336 5dc97367-97…
alobbs authored
133 cherokee_buffer_add_str (buf, " HTTP/1.1" CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
134 break;
135 case http_version_10:
6363e73 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@336 5dc97367-97…
alobbs authored
136 cherokee_buffer_add_str (buf, " HTTP/1.0" CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
137 break;
138 default:
139 SHOULDNT_HAPPEN;
af033e6 removed other statements involved in HTTP/0.9 support (which has just…
ADF authored
140 return ret_error;
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
141 }
142
143 /* Add "Host:" header - in HTTP/1.1
144 */
145 if (REQUEST_VERSION(request) == http_version_11) {
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
146 cherokee_buffer_add_str (buf, "Host: ");
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
147 cherokee_buffer_add_buffer (buf, URL_HOST(url));
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
148 cherokee_buffer_add_str (buf, CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
149 }
150
151 /* Post information
152 */
153 if (request->post_len != 0) {
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
154 /* "Content-Length: " FMT_OFFSET CRLF, request->post_len;
155 */
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
156 cherokee_buffer_add_str (buf, "Content-Length: ");
157 cherokee_buffer_add_ullong10 (buf, (cullong_t) request->post_len);
158 cherokee_buffer_add_str (buf, CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
159 }
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
160
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
161 /* Add "Connection:" header
162 */
163 if (REQUEST_KEEPALIVE(request)) {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
164 cherokee_buffer_add_str (buf, "Connection: Keep-Alive"CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
165 } else {
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
166 cherokee_buffer_add_str (buf, "Connection: close"CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
167 }
168
169 /* Authentication
170 */
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
171 if (! cherokee_buffer_is_empty (&request->user) ||
172 ! cherokee_buffer_is_empty (&request->password)) {
3c2b494 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97…
alobbs authored
173 cherokee_buffer_clean (tmp1);
174 cherokee_buffer_clean (tmp2);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
175
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
176 cherokee_buffer_add_buffer (tmp1, &request->user);
3c2b494 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97…
alobbs authored
177 cherokee_buffer_add_char (tmp1, ':');
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
178 cherokee_buffer_add_buffer (tmp1, &request->password);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
179
3c2b494 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97…
alobbs authored
180 cherokee_buffer_encode_base64 (tmp1, tmp2);
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
181
3c2b494 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@606 5dc97367-97…
alobbs authored
182 cherokee_buffer_add_str (buf, "Authorization: Basic ");
183 cherokee_buffer_add_buffer (buf, tmp2);
184 cherokee_buffer_add_str (buf, CRLF);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
185 }
186
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
187 /* Extra headers
188 */
189 if (! cherokee_buffer_is_empty (&request->extra_headers)) {
190 cherokee_buffer_add_buffer (buf, &request->extra_headers);
191 }
192
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
193 /* Finish the header
194 */
6363e73 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@336 5dc97367-97…
alobbs authored
195 cherokee_buffer_add_str (buf, CRLF);
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
196 return ret_ok;
197 }
198
199
200 ret_t
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
201 cherokee_request_header_set_auth (cherokee_request_header_t *request,
eb566f9 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@948 5dc97367-97…
alobbs authored
202 cherokee_http_auth_t auth,
203 cherokee_buffer_t *user,
204 cherokee_buffer_t *password)
205 {
206 request->auth = auth;
207
208 cherokee_buffer_clean (&request->user);
209 cherokee_buffer_clean (&request->password);
210
211 cherokee_buffer_add_buffer (&request->user, user);
212 cherokee_buffer_add_buffer (&request->password, password);
ae9d971 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@243 5dc97367-97…
alobbs authored
213
214 return ret_ok;
215 }
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
216
af033e6 removed other statements involved in HTTP/0.9 support (which has just…
ADF authored
217
72f6444 @alobbs Clean up: Trims trailing spaces.
alobbs authored
218 ret_t
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
219 cherokee_request_header_add_header (cherokee_request_header_t *request, char *ptr, cuint_t len)
220 {
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
221 cherokee_buffer_ensure_addlen (&request->extra_headers, len + CSZLEN(CRLF));
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
222 cherokee_buffer_add (&request->extra_headers, ptr, len);
936d90b @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@602 5dc97367-97…
alobbs authored
223 cherokee_buffer_add_str (&request->extra_headers, CRLF);
af11404 @alobbs git-svn-id: svn://cherokee-project.com/cherokee/trunk@253 5dc97367-97…
alobbs authored
224
225 return ret_ok;
226 }
Something went wrong with that request. Please try again.