annotate src/core/ngx_crc.h @ 4147:7f64de1cc2c0

Fix for double content when return is used in error_page handler. Test case: location / { error_page 405 /nope; return 405; } location /nope { return 200; } This is expected to return 405 with empty body, but in 0.8.42+ will return builtin 405 error page as well (though not counted in Content-Length, thus breaking protocol). Fix is to use status provided by rewrite script execution in case it's less than NGX_HTTP_BAD_REQUEST even if r->error_status set. This check is in line with one in ngx_http_script_return_code(). Note that this patch also changes behaviour for "return 302 ..." and "rewrite ... redirect" used as error handler. E.g. location / { error_page 405 /redirect; return 405; } location /redirect { rewrite ^ http://example.com/; } will actually return redirect to "http://example.com/" instead of builtin 405 error page with meaningless Location header. This looks like correct change and it's in line with what happens on e.g. directory redirects in error handlers.
author Maxim Dounin <mdounin@mdounin.ru>
date Tue, 27 Sep 2011 11:11:30 +0000
parents 99858705b03f
children d620f497c50f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
4 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
5
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
6
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #ifndef _NGX_CRC_H_INCLUDED_
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #define _NGX_CRC_H_INCLUDED_
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
792
99858705b03f add includes
Igor Sysoev <igor@sysoev.ru>
parents: 789
diff changeset
11 #include <ngx_config.h>
99858705b03f add includes
Igor Sysoev <igor@sysoev.ru>
parents: 789
diff changeset
12 #include <ngx_core.h>
99858705b03f add includes
Igor Sysoev <igor@sysoev.ru>
parents: 789
diff changeset
13
99858705b03f add includes
Igor Sysoev <igor@sysoev.ru>
parents: 789
diff changeset
14
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 /* 32-bit crc16 */
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16
776
5622cdd48e5b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
17 static ngx_inline uint32_t
789
604f9671fae6 char* > u_char*
Igor Sysoev <igor@sysoev.ru>
parents: 776
diff changeset
18 ngx_crc(u_char *data, size_t len)
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 {
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20 uint32_t sum;
208
0b67be7d4489 nginx-0.0.1-2003-12-08-23:48:12 import
Igor Sysoev <igor@sysoev.ru>
parents: 201
diff changeset
21
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22 for (sum = 0; len; len--) {
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 208
diff changeset
23
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 /*
776
5622cdd48e5b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
25 * gcc 2.95.2 x86 and icc 7.1.006 compile
5622cdd48e5b style fix
Igor Sysoev <igor@sysoev.ru>
parents: 467
diff changeset
26 * that operator into the single "rol" opcode,
201
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27 * msvc 6.0sp2 compiles it into four opcodes.
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 */
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 sum = sum >> 1 | sum << 31;
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31 sum += *data++;
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 }
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 return sum;
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35 }
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
36
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
37
267ea1d98683 nginx-0.0.1-2003-11-30-23:03:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 #endif /* _NGX_CRC_H_INCLUDED_ */