Merge lp:~fourkitchens/pressflow/6-evented into lp:pressflow
- 6-evented
- Merge into 6
Status: | Work in progress |
---|---|
Proposed branch: | lp:~fourkitchens/pressflow/6-evented |
Merge into: | lp:pressflow |
Diff against target: |
485 lines (+340/-18) 6 files modified
DaemonRequest.php (+58/-0) DaemonResponse.php (+139/-0) evented-daemon.php (+120/-0) includes/bootstrap.inc (+12/-10) includes/common.inc (+10/-8) themes/garland/page.tpl.php (+1/-0) |
To merge this branch: | bzr merge lp:~fourkitchens/pressflow/6-evented |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Pressflow Administrators | Pending | ||
Review via email: mp+29770@code.launchpad.net |
Commit message
Description of the change
- 88. By Aaron Forsander
-
Added very basic support for static files.
- 89. By Aaron Forsander
-
Drupal's .htaccess doesn't set q with the leading / and it trims trailing slashes anyways.
- 90. By Aaron Forsander
-
Created DaemonRequest and DaemonResponse classes to make working with requests and responses a little easier. Trying to figure out the appropriate session setup/teardown per request.
- 91. By Aaron Forsander
-
Cleaning up log output.
- 92. By David Strauss
-
Merge from 6.x trunk.
Unmerged revisions
- 92. By David Strauss
-
Merge from 6.x trunk.
- 91. By Aaron Forsander
-
Cleaning up log output.
- 90. By Aaron Forsander
-
Created DaemonRequest and DaemonResponse classes to make working with requests and responses a little easier. Trying to figure out the appropriate session setup/teardown per request.
- 89. By Aaron Forsander
-
Drupal's .htaccess doesn't set q with the leading / and it trims trailing slashes anyways.
- 88. By Aaron Forsander
-
Added very basic support for static files.
- 87. By David Strauss
-
Make the port number for the daemon a shell argument.
- 86. By David Strauss
-
Initial event-driven system.
Preview Diff
1 | === added file 'DaemonRequest.php' | |||
2 | --- DaemonRequest.php 1970-01-01 00:00:00 +0000 | |||
3 | +++ DaemonRequest.php 2010-08-22 07:23:38 +0000 | |||
4 | @@ -0,0 +1,58 @@ | |||
5 | 1 | <?php | ||
6 | 2 | |||
7 | 3 | class DaemonRequest { | ||
8 | 4 | public $request; | ||
9 | 5 | public $method = ''; | ||
10 | 6 | public $uri = ''; | ||
11 | 7 | public $query_string = ''; | ||
12 | 8 | public $path = ''; | ||
13 | 9 | public $headers = array(); | ||
14 | 10 | public $body = ''; | ||
15 | 11 | |||
16 | 12 | public function __construct($evhttp_request) { | ||
17 | 13 | $this->request = $evhttp_request; | ||
18 | 14 | $this->method = evhttp_request_method($this->request); | ||
19 | 15 | $this->uri = evhttp_request_uri($this->request); | ||
20 | 16 | $this->headers = evhttp_request_headers($this->request); | ||
21 | 17 | $this->body = evhttp_request_body($this->request); | ||
22 | 18 | $this->query_string = parse_url($this->uri, PHP_URL_QUERY); | ||
23 | 19 | $this->path = parse_url($this->uri, PHP_URL_PATH); | ||
24 | 20 | } | ||
25 | 21 | |||
26 | 22 | public function init() { | ||
27 | 23 | // Reset request-specific globals | ||
28 | 24 | foreach (array('_COOKIE', '_POST', '_GET', '_FILES', '_SESSION') as $global) { | ||
29 | 25 | $GLOBALS[$global] = array(); | ||
30 | 26 | } | ||
31 | 27 | |||
32 | 28 | // Initialize SERVER data | ||
33 | 29 | $_SERVER["REQUEST_METHOD"] = $this->method; | ||
34 | 30 | $_SERVER["REQUEST_TIME"] = time(); | ||
35 | 31 | $_SERVER["argv"] = $_SERVER["REQUEST_URI"] = $this->uri; | ||
36 | 32 | |||
37 | 33 | // Initialize HTTP data | ||
38 | 34 | foreach ($this->headers as $name => $value) { | ||
39 | 35 | $_SERVER["HTTP_" . str_replace("-", "_", strtoupper($name))] = $value; | ||
40 | 36 | } | ||
41 | 37 | |||
42 | 38 | // Initialize POST data | ||
43 | 39 | if ($this->method === "POST") { | ||
44 | 40 | parse_str($this->body, $_POST); | ||
45 | 41 | } | ||
46 | 42 | |||
47 | 43 | // Initialize GET data | ||
48 | 44 | $_SERVER['QUERY_STRING'] = $this->query_string; | ||
49 | 45 | parse_str($this->query_string, $_GET); | ||
50 | 46 | $_GET['q'] = trim($this->path, '/'); | ||
51 | 47 | |||
52 | 48 | // Initialize COOKIE data | ||
53 | 49 | if ($this->headers['Cookie']) { | ||
54 | 50 | $cookies = explode(';', $this->headers['Cookie']); | ||
55 | 51 | foreach ($cookies as $cookie) { | ||
56 | 52 | list($name, $value) = explode('=', $cookie); | ||
57 | 53 | $_COOKIE[$name] = $value; | ||
58 | 54 | } | ||
59 | 55 | } | ||
60 | 56 | } | ||
61 | 57 | } | ||
62 | 58 | |||
63 | 0 | 59 | ||
64 | === added file 'DaemonResponse.php' | |||
65 | --- DaemonResponse.php 1970-01-01 00:00:00 +0000 | |||
66 | +++ DaemonResponse.php 2010-08-22 07:23:38 +0000 | |||
67 | @@ -0,0 +1,139 @@ | |||
68 | 1 | <?php | ||
69 | 2 | class DaemonResponse { | ||
70 | 3 | public $request; | ||
71 | 4 | public $response; | ||
72 | 5 | public $code; | ||
73 | 6 | public $body; | ||
74 | 7 | public $headers = array(); | ||
75 | 8 | |||
76 | 9 | public static $messages = array( | ||
77 | 10 | // Informational 1xx | ||
78 | 11 | 100 => 'Continue', | ||
79 | 12 | 101 => 'Switching Protocols', | ||
80 | 13 | |||
81 | 14 | // Success 2xx | ||
82 | 15 | 200 => 'OK', | ||
83 | 16 | 201 => 'Created', | ||
84 | 17 | 202 => 'Accepted', | ||
85 | 18 | 203 => 'Non-Authoritative Information', | ||
86 | 19 | 204 => 'No Content', | ||
87 | 20 | 205 => 'Reset Content', | ||
88 | 21 | 206 => 'Partial Content', | ||
89 | 22 | 207 => 'Multi-Status', | ||
90 | 23 | |||
91 | 24 | // Redirection 3xx | ||
92 | 25 | 300 => 'Multiple Choices', | ||
93 | 26 | 301 => 'Moved Permanently', | ||
94 | 27 | 302 => 'Found', // 1.1 | ||
95 | 28 | 303 => 'See Other', | ||
96 | 29 | 304 => 'Not Modified', | ||
97 | 30 | 305 => 'Use Proxy', | ||
98 | 31 | // 306 is deprecated but reserved | ||
99 | 32 | 307 => 'Temporary Redirect', | ||
100 | 33 | |||
101 | 34 | // Client Error 4xx | ||
102 | 35 | 400 => 'Bad Request', | ||
103 | 36 | 401 => 'Unauthorized', | ||
104 | 37 | 402 => 'Payment Required', | ||
105 | 38 | 403 => 'Forbidden', | ||
106 | 39 | 404 => 'Not Found', | ||
107 | 40 | 405 => 'Method Not Allowed', | ||
108 | 41 | 406 => 'Not Acceptable', | ||
109 | 42 | 407 => 'Proxy Authentication Required', | ||
110 | 43 | 408 => 'Request Timeout', | ||
111 | 44 | 409 => 'Conflict', | ||
112 | 45 | 410 => 'Gone', | ||
113 | 46 | 411 => 'Length Required', | ||
114 | 47 | 412 => 'Precondition Failed', | ||
115 | 48 | 413 => 'Request Entity Too Large', | ||
116 | 49 | 414 => 'Request-URI Too Long', | ||
117 | 50 | 415 => 'Unsupported Media Type', | ||
118 | 51 | 416 => 'Requested Range Not Satisfiable', | ||
119 | 52 | 417 => 'Expectation Failed', | ||
120 | 53 | 422 => 'Unprocessable Entity', | ||
121 | 54 | 423 => 'Locked', | ||
122 | 55 | 424 => 'Failed Dependency', | ||
123 | 56 | |||
124 | 57 | // Server Error 5xx | ||
125 | 58 | 500 => 'Internal Server Error', | ||
126 | 59 | 501 => 'Not Implemented', | ||
127 | 60 | 502 => 'Bad Gateway', | ||
128 | 61 | 503 => 'Service Unavailable', | ||
129 | 62 | 504 => 'Gateway Timeout', | ||
130 | 63 | 505 => 'HTTP Version Not Supported', | ||
131 | 64 | 507 => 'Insufficient Storage', | ||
132 | 65 | 509 => 'Bandwidth Limit Exceeded' | ||
133 | 66 | ); | ||
134 | 67 | |||
135 | 68 | public function __construct($request) { | ||
136 | 69 | $this->request = $request; | ||
137 | 70 | } | ||
138 | 71 | |||
139 | 72 | public function addHeader($type, $content) { | ||
140 | 73 | $this->headers[] = array($type, $content); | ||
141 | 74 | return $this; | ||
142 | 75 | } | ||
143 | 76 | |||
144 | 77 | public function setBody($body = '') { | ||
145 | 78 | $this->body = $body; | ||
146 | 79 | return $this; | ||
147 | 80 | } | ||
148 | 81 | |||
149 | 82 | public function getBody() { | ||
150 | 83 | return $this->body; | ||
151 | 84 | } | ||
152 | 85 | |||
153 | 86 | public function setCode($code = 500) { | ||
154 | 87 | $this->code = $code; | ||
155 | 88 | return $this; | ||
156 | 89 | } | ||
157 | 90 | |||
158 | 91 | public function getCode() { | ||
159 | 92 | return $this->code; | ||
160 | 93 | } | ||
161 | 94 | |||
162 | 95 | public function setResponse($body = NULL, $code = NULL) { | ||
163 | 96 | $body = $body ? $body : $this->getBody(); | ||
164 | 97 | $code = $code ? $code : $this->getCode(); | ||
165 | 98 | |||
166 | 99 | foreach ($this->headers as $header) { | ||
167 | 100 | evhttp_response_add_header($this->request->request, $header[0], $header[1]); | ||
168 | 101 | } | ||
169 | 102 | |||
170 | 103 | $this->response = evhttp_response_set($body, $code, self::$messages[$code]); | ||
171 | 104 | return $this; | ||
172 | 105 | } | ||
173 | 106 | |||
174 | 107 | public function getResponse() { | ||
175 | 108 | $this->setResponse(); | ||
176 | 109 | return $this->response; | ||
177 | 110 | } | ||
178 | 111 | |||
179 | 112 | public function setCookie($name, $value = '', $maxage = 0, $path = '', $domain = '', $secure = false, $HTTPOnly = false) { | ||
180 | 113 | if ($domain) { | ||
181 | 114 | if (strtolower(substr($domain, 0, 4)) == 'www.') { | ||
182 | 115 | $domain = substr($domain, 4); | ||
183 | 116 | } | ||
184 | 117 | |||
185 | 118 | if ($domain[0] != '.') { | ||
186 | 119 | $domain = '.'.$domain; | ||
187 | 120 | } | ||
188 | 121 | |||
189 | 122 | $port = strpos($domain, ':'); | ||
190 | 123 | if ($port !== FALSE) { | ||
191 | 124 | $domain = substr($domain, 0, $port); | ||
192 | 125 | } | ||
193 | 126 | } | ||
194 | 127 | |||
195 | 128 | $header = rawurlencode($name).'='.rawurlencode($value) | ||
196 | 129 | .(empty($domain) ? '' : '; Domain='.$domain) | ||
197 | 130 | .(empty($maxage) ? '' : '; Max-Age='.$maxage) | ||
198 | 131 | .(empty($path) ? '' : '; Path='.$path) | ||
199 | 132 | .(!$secure ? '' : '; Secure') | ||
200 | 133 | .(!$HTTPOnly ? '' : '; HttpOnly'); | ||
201 | 134 | |||
202 | 135 | evhttp_response_add_header($this->request->request, 'Set-Cookie', $header); | ||
203 | 136 | return $this; | ||
204 | 137 | } | ||
205 | 138 | } | ||
206 | 139 | |||
207 | 0 | 140 | ||
208 | === added file 'evented-daemon.php' | |||
209 | --- evented-daemon.php 1970-01-01 00:00:00 +0000 | |||
210 | +++ evented-daemon.php 2010-08-22 07:23:38 +0000 | |||
211 | @@ -0,0 +1,120 @@ | |||
212 | 1 | <?php | ||
213 | 2 | |||
214 | 3 | require_once 'DaemonRequest.php'; | ||
215 | 4 | require_once 'DaemonResponse.php'; | ||
216 | 5 | |||
217 | 6 | /** | ||
218 | 7 | * Perform generic bootstrapping for daemonized requests. | ||
219 | 8 | */ | ||
220 | 9 | function daemon_initialize() { | ||
221 | 10 | global $conf; | ||
222 | 11 | require_once './includes/bootstrap.inc'; | ||
223 | 12 | require_once './includes/path.inc'; | ||
224 | 13 | require_once './includes/common.inc'; | ||
225 | 14 | require_once './includes/module.inc'; | ||
226 | 15 | drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE, TRUE); | ||
227 | 16 | $conf = variable_init(isset($conf) ? $conf : array()); | ||
228 | 17 | require_once variable_get('session_inc', './includes/session.inc'); | ||
229 | 18 | _drupal_bootstrap_full(TRUE); | ||
230 | 19 | daemon_log('Base daemon initialized'); | ||
231 | 20 | } | ||
232 | 21 | |||
233 | 22 | function daemon_log($msg) { | ||
234 | 23 | echo date("c") . " [Pressflow] $msg" . PHP_EOL; | ||
235 | 24 | return; | ||
236 | 25 | } | ||
237 | 26 | |||
238 | 27 | /** | ||
239 | 28 | * Handle an individual request. | ||
240 | 29 | */ | ||
241 | 30 | function daemon_request_callback(DaemonRequest $request) { | ||
242 | 31 | $start = microtime(TRUE); | ||
243 | 32 | global $user; | ||
244 | 33 | |||
245 | 34 | // Initialize our response object | ||
246 | 35 | $response = new DaemonResponse($request); | ||
247 | 36 | |||
248 | 37 | // MEGAHACK! Your mother would be ashamed! There is no way around it! This needs | ||
249 | 38 | // to be available to the rest of Drupal so it can set headers and whatnot. This | ||
250 | 39 | // causes a segfault unless it is cleaned up at the end of _daemon_request_callback. | ||
251 | 40 | $GLOBALS['response'] = $response; | ||
252 | 41 | |||
253 | 42 | // Initialize server | ||
254 | 43 | $request->init(); | ||
255 | 44 | |||
256 | 45 | daemon_log('Using path: ' . $_GET['q']); | ||
257 | 46 | |||
258 | 47 | // Start a new session | ||
259 | 48 | drupal_session_started(FALSE); | ||
260 | 49 | drupal_session_initialize(); | ||
261 | 50 | if (!isset($_COOKIE[session_name()])) { | ||
262 | 51 | $user = drupal_anonymous_user(); | ||
263 | 52 | $session_id = session_id(md5(uniqid('', TRUE))); | ||
264 | 53 | $response->setCookie(session_name(), $session_id); | ||
265 | 54 | } | ||
266 | 55 | |||
267 | 56 | // Initialize Drupal | ||
268 | 57 | bootstrap_invoke_all('boot'); | ||
269 | 58 | module_list(TRUE, FALSE); | ||
270 | 59 | drupal_init_language(); | ||
271 | 60 | drupal_init_path(); | ||
272 | 61 | module_invoke_all('init'); | ||
273 | 62 | |||
274 | 63 | // Hack to handle static files | ||
275 | 64 | $static_file_types = array('js' => 'application/x-javascript', 'css' => 'text/css', 'png' => 'image/png', | ||
276 | 65 | 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'gif' => 'image/gif', 'bmp' => 'image/bmp', | ||
277 | 66 | 'ico' => 'image/x-icon'); | ||
278 | 67 | $ext = pathinfo($_GET['q'], PATHINFO_EXTENSION); | ||
279 | 68 | if (isset($static_file_types[$ext]) && file_exists($_GET['q']) && strpos(realpath($_GET['q']), getcwd()) === 0) { | ||
280 | 69 | return $response->addHeader('Content-type', $static_file_types[$ext])->setBody(file_get_contents($_GET['q']))->setCode(200); | ||
281 | 70 | } | ||
282 | 71 | else { | ||
283 | 72 | $response->addHeader('Content-type', 'text/html; charset=utf-8'); | ||
284 | 73 | } | ||
285 | 74 | |||
286 | 75 | // Execute the appropriate menu handler. | ||
287 | 76 | $return = menu_execute_active_handler(); | ||
288 | 77 | |||
289 | 78 | // Menu status constants are integers; page content is a string. | ||
290 | 79 | if (is_int($return)) { | ||
291 | 80 | switch ($return) { | ||
292 | 81 | case MENU_NOT_FOUND: | ||
293 | 82 | daemon_log('Response: Not found'); | ||
294 | 83 | return $response->setBody('Not found.')->setCode(404); | ||
295 | 84 | case MENU_ACCESS_DENIED: | ||
296 | 85 | daemon_log('Response: Access denied'); | ||
297 | 86 | return $response->setBody('Access denied.')->setCode(403); | ||
298 | 87 | case MENU_SITE_OFFLINE: | ||
299 | 88 | daemon_log('Response: Site offline'); | ||
300 | 89 | return $response->setBody('Service unavailable.')->setCode(503); | ||
301 | 90 | } | ||
302 | 91 | } | ||
303 | 92 | elseif (isset($return)) { | ||
304 | 93 | // Print any value (including an empty string) except NULL or undefined: | ||
305 | 94 | $res = theme('page', $return); | ||
306 | 95 | } | ||
307 | 96 | |||
308 | 97 | drupal_page_footer(); | ||
309 | 98 | session_write_close(); | ||
310 | 99 | return $response->setBody($res)->setCode(200); | ||
311 | 100 | } | ||
312 | 101 | |||
313 | 102 | function _daemon_request_callback($evhttp_request) { | ||
314 | 103 | $response = daemon_request_callback(new DaemonRequest($evhttp_request)); | ||
315 | 104 | unset($GLOBALS['response']); | ||
316 | 105 | return $response->getResponse(); | ||
317 | 106 | } | ||
318 | 107 | |||
319 | 108 | if (!extension_loaded('event')) { | ||
320 | 109 | dl('event.' . PHP_SHLIB_SUFFIX); | ||
321 | 110 | } | ||
322 | 111 | |||
323 | 112 | error_reporting(E_ALL & ~E_NOTICE); | ||
324 | 113 | ini_set('display_errors', 1); | ||
325 | 114 | |||
326 | 115 | daemon_initialize(); | ||
327 | 116 | event_init(); | ||
328 | 117 | $httpd = evhttp_start('0.0.0.0', $argv[1]); | ||
329 | 118 | evhttp_set_gencb($httpd, '_daemon_request_callback'); | ||
330 | 119 | event_dispatch(); | ||
331 | 120 | |||
332 | 0 | 121 | ||
333 | === modified file 'includes/bootstrap.inc' | |||
334 | --- includes/bootstrap.inc 2010-08-11 21:05:18 +0000 | |||
335 | +++ includes/bootstrap.inc 2010-08-22 07:23:38 +0000 | |||
336 | @@ -1400,14 +1400,14 @@ | |||
337 | 1400 | * DRUPAL_BOOTSTRAP_PATH: set $_GET['q'] to Drupal path of request. | 1400 | * DRUPAL_BOOTSTRAP_PATH: set $_GET['q'] to Drupal path of request. |
338 | 1401 | * DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data. | 1401 | * DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data. |
339 | 1402 | */ | 1402 | */ |
341 | 1403 | function drupal_bootstrap($phase = NULL) { | 1403 | function drupal_bootstrap($phase = NULL, $daemonized = FALSE) { |
342 | 1404 | static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0; | 1404 | static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL), $phase_index = 0; |
343 | 1405 | 1405 | ||
344 | 1406 | if (isset($phase)) { | 1406 | if (isset($phase)) { |
345 | 1407 | while ($phase >= $phase_index && isset($phases[$phase_index])) { | 1407 | while ($phase >= $phase_index && isset($phases[$phase_index])) { |
346 | 1408 | $current_phase = $phases[$phase_index]; | 1408 | $current_phase = $phases[$phase_index]; |
347 | 1409 | unset($phases[$phase_index++]); | 1409 | unset($phases[$phase_index++]); |
349 | 1410 | _drupal_bootstrap($current_phase); | 1410 | _drupal_bootstrap($current_phase, $daemonized); |
350 | 1411 | } | 1411 | } |
351 | 1412 | } | 1412 | } |
352 | 1413 | 1413 | ||
353 | @@ -1424,7 +1424,7 @@ | |||
354 | 1424 | } | 1424 | } |
355 | 1425 | } | 1425 | } |
356 | 1426 | 1426 | ||
358 | 1427 | function _drupal_bootstrap($phase) { | 1427 | function _drupal_bootstrap($phase, $daemonized) { |
359 | 1428 | global $conf, $user, $db_prefix; | 1428 | global $conf, $user, $db_prefix; |
360 | 1429 | 1429 | ||
361 | 1430 | switch ($phase) { | 1430 | switch ($phase) { |
362 | @@ -1478,11 +1478,9 @@ | |||
363 | 1478 | 1478 | ||
364 | 1479 | case DRUPAL_BOOTSTRAP_ACCESS: | 1479 | case DRUPAL_BOOTSTRAP_ACCESS: |
365 | 1480 | // Deny access to hosts which were banned - t() is not yet available. | 1480 | // Deny access to hosts which were banned - t() is not yet available. |
371 | 1481 | if (drupal_is_denied('host', ip_address())) { | 1481 | header('HTTP/1.1 403 Forbidden'); |
372 | 1482 | header('HTTP/1.1 403 Forbidden'); | 1482 | print 'Sorry, '. check_plain(ip_address()) .' has been banned.'; |
373 | 1483 | print 'Sorry, '. check_plain(ip_address()) .' has been banned.'; | 1483 | exit(); |
369 | 1484 | exit(); | ||
370 | 1485 | } | ||
374 | 1486 | break; | 1484 | break; |
375 | 1487 | 1485 | ||
376 | 1488 | case DRUPAL_BOOTSTRAP_SESSION: | 1486 | case DRUPAL_BOOTSTRAP_SESSION: |
377 | @@ -1665,7 +1663,10 @@ | |||
378 | 1665 | static $ip_address = NULL; | 1663 | static $ip_address = NULL; |
379 | 1666 | 1664 | ||
380 | 1667 | if (!isset($ip_address)) { | 1665 | if (!isset($ip_address)) { |
382 | 1668 | $ip_address = $_SERVER['REMOTE_ADDR']; | 1666 | $ip_address = '127.0.0.1'; |
383 | 1667 | if (isset($_SERVER['REMOTE_ADDR'])) { | ||
384 | 1668 | $ip_address = $_SERVER['REMOTE_ADDR']; | ||
385 | 1669 | } | ||
386 | 1669 | 1670 | ||
387 | 1670 | // Only use parts of the X-Forwarded-For (XFF) header that have followed a trusted route. | 1671 | // Only use parts of the X-Forwarded-For (XFF) header that have followed a trusted route. |
388 | 1671 | // Specifically, identify the leftmost IP address in the XFF header that is not one of ours. | 1672 | // Specifically, identify the leftmost IP address in the XFF header that is not one of ours. |
389 | @@ -1699,7 +1700,7 @@ | |||
390 | 1699 | */ | 1700 | */ |
391 | 1700 | function drupal_session_initialize() { | 1701 | function drupal_session_initialize() { |
392 | 1701 | global $user; | 1702 | global $user; |
394 | 1702 | 1703 | ||
395 | 1703 | session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc'); | 1704 | session_set_save_handler('sess_open', 'sess_close', 'sess_read', 'sess_write', 'sess_destroy_sid', 'sess_gc'); |
396 | 1704 | 1705 | ||
397 | 1705 | if (isset($_COOKIE[session_name()])) { | 1706 | if (isset($_COOKIE[session_name()])) { |
398 | @@ -1823,6 +1824,7 @@ | |||
399 | 1823 | */ | 1824 | */ |
400 | 1824 | function drupal_save_session($status = NULL) { | 1825 | function drupal_save_session($status = NULL) { |
401 | 1825 | static $save_session = TRUE; | 1826 | static $save_session = TRUE; |
402 | 1827 | |||
403 | 1826 | if (isset($status)) { | 1828 | if (isset($status)) { |
404 | 1827 | $save_session = $status; | 1829 | $save_session = $status; |
405 | 1828 | } | 1830 | } |
406 | 1829 | 1831 | ||
407 | === modified file 'includes/common.inc' | |||
408 | --- includes/common.inc 2010-08-11 21:05:18 +0000 | |||
409 | +++ includes/common.inc 2010-08-22 07:23:38 +0000 | |||
410 | @@ -303,6 +303,7 @@ | |||
411 | 303 | * @see drupal_get_destination() | 303 | * @see drupal_get_destination() |
412 | 304 | */ | 304 | */ |
413 | 305 | function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) { | 305 | function drupal_goto($path = '', $query = NULL, $fragment = NULL, $http_response_code = 302) { |
414 | 306 | global $response; | ||
415 | 306 | 307 | ||
416 | 307 | $destination = FALSE; | 308 | $destination = FALSE; |
417 | 308 | if (isset($_REQUEST['destination'])) { | 309 | if (isset($_REQUEST['destination'])) { |
418 | @@ -335,12 +336,13 @@ | |||
419 | 335 | // we need all session data written to the database before redirecting. | 336 | // we need all session data written to the database before redirecting. |
420 | 336 | drupal_session_commit(); | 337 | drupal_session_commit(); |
421 | 337 | 338 | ||
423 | 338 | header('Location: '. $url, TRUE, $http_response_code); | 339 | // header('Location: '. $url, TRUE, $http_response_code); |
424 | 340 | $response->addHeader($http_response_code, 'Location: '. $url); | ||
425 | 339 | 341 | ||
426 | 340 | // The "Location" header sends a redirect status code to the HTTP daemon. In | 342 | // The "Location" header sends a redirect status code to the HTTP daemon. In |
427 | 341 | // some cases this can be wrong, so we make sure none of the code below the | 343 | // some cases this can be wrong, so we make sure none of the code below the |
428 | 342 | // drupal_goto() call gets executed upon redirection. | 344 | // drupal_goto() call gets executed upon redirection. |
430 | 343 | exit(); | 345 | // exit(); |
431 | 344 | } | 346 | } |
432 | 345 | 347 | ||
433 | 346 | /** | 348 | /** |
434 | @@ -1465,7 +1467,7 @@ | |||
435 | 1465 | global $base_url; | 1467 | global $base_url; |
436 | 1466 | static $script; | 1468 | static $script; |
437 | 1467 | 1469 | ||
439 | 1468 | if (!isset($script)) { | 1470 | if (!isset($script) && isset($_SERVER['SERVER_SOFTWARE'])) { |
440 | 1469 | // On some web servers, such as IIS, we can't omit "index.php". So, we | 1471 | // On some web servers, such as IIS, we can't omit "index.php". So, we |
441 | 1470 | // generate "index.php?q=foo" instead of "?q=foo" on anything that is not | 1472 | // generate "index.php?q=foo" instead of "?q=foo" on anything that is not |
442 | 1471 | // Apache. | 1473 | // Apache. |
443 | @@ -2611,7 +2613,7 @@ | |||
444 | 2611 | return call_user_func_array('_xmlrpc', $args); | 2613 | return call_user_func_array('_xmlrpc', $args); |
445 | 2612 | } | 2614 | } |
446 | 2613 | 2615 | ||
448 | 2614 | function _drupal_bootstrap_full() { | 2616 | function _drupal_bootstrap_full($daemonized = FALSE) { |
449 | 2615 | static $called; | 2617 | static $called; |
450 | 2616 | 2618 | ||
451 | 2617 | if ($called) { | 2619 | if ($called) { |
452 | @@ -2629,10 +2631,10 @@ | |||
453 | 2629 | require_once './includes/mail.inc'; | 2631 | require_once './includes/mail.inc'; |
454 | 2630 | require_once './includes/actions.inc'; | 2632 | require_once './includes/actions.inc'; |
455 | 2631 | // Set the Drupal custom error handler. | 2633 | // Set the Drupal custom error handler. |
458 | 2632 | set_error_handler('_drupal_error_handler'); | 2634 | //set_error_handler('_drupal_error_handler'); |
459 | 2633 | set_exception_handler('_drupal_exception_handler'); | 2635 | //set_exception_handler('_drupal_exception_handler'); |
460 | 2634 | // Emit the correct charset HTTP header. | 2636 | // Emit the correct charset HTTP header. |
462 | 2635 | drupal_set_header('Content-Type: text/html; charset=utf-8'); | 2637 | //drupal_set_header('Content-Type: text/html; charset=utf-8'); |
463 | 2636 | // Detect string handling method | 2638 | // Detect string handling method |
464 | 2637 | unicode_check(); | 2639 | unicode_check(); |
465 | 2638 | // Undo magic quotes | 2640 | // Undo magic quotes |
466 | @@ -2650,7 +2652,7 @@ | |||
467 | 2650 | module_load_all(); | 2652 | module_load_all(); |
468 | 2651 | // Let all modules take action before menu system handles the request | 2653 | // Let all modules take action before menu system handles the request |
469 | 2652 | // We do not want this while running update.php. | 2654 | // We do not want this while running update.php. |
471 | 2653 | if (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update') { | 2655 | if (!$daemonized && (!defined('MAINTENANCE_MODE') || MAINTENANCE_MODE != 'update')) { |
472 | 2654 | module_invoke_all('init'); | 2656 | module_invoke_all('init'); |
473 | 2655 | } | 2657 | } |
474 | 2656 | } | 2658 | } |
475 | 2657 | 2659 | ||
476 | === modified file 'themes/garland/page.tpl.php' | |||
477 | --- themes/garland/page.tpl.php 2009-04-30 00:36:53 +0000 | |||
478 | +++ themes/garland/page.tpl.php 2010-08-22 07:23:38 +0000 | |||
479 | @@ -91,5 +91,6 @@ | |||
480 | 91 | <!-- /layout --> | 91 | <!-- /layout --> |
481 | 92 | 92 | ||
482 | 93 | <?php print $closure ?> | 93 | <?php print $closure ?> |
483 | 94 | <?php foreach (array($_POST, $_GET, $_COOKIE) as $global) echo print_r($global, TRUE).'<br />'; ?> | ||
484 | 94 | </body> | 95 | </body> |
485 | 95 | </html> | 96 | </html> |