Mercurial > hg > nginx
annotate src/os/win32/ngx_errno.c @ 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 | e294f37401c0 |
children | d620f497c50f |
rev | line source |
---|---|
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
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:
186
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:
186
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:
186
diff
changeset
|
6 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
8 #include <ngx_core.h> |
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
9 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
2335
3d8ab5957202
ngx_strerror_r() style and size == 0 bug fix
Igor Sysoev <igor@sysoev.ru>
parents:
473
diff
changeset
|
11 u_char * |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
12 ngx_strerror(ngx_err_t err, u_char *errstr, size_t size) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 { |
2770
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
14 u_int len; |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
15 static u_long lang = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
461 | 17 if (size == 0) { |
18 return errstr; | |
19 } | |
20 | |
2770
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
21 len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
22 NULL, err, lang, (char *) errstr, size, NULL); |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
23 |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
24 if (len == 0 && lang && GetLastError() == ERROR_RESOURCE_LANG_NOT_FOUND) { |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
25 |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
26 /* |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
27 * Try to use English messages first and fallback to a language, |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
28 * based on locale: non-English Windows have no English messages |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
29 * at all. This way allows to use English messages at least on |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
30 * Windows with MUI. |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
31 */ |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
32 |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
33 lang = 0; |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
34 |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
35 len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
36 NULL, err, lang, (char *) errstr, size, NULL); |
e70ac6e13f31
fallback to neutral language in FormatMessage()
Igor Sysoev <igor@sysoev.ru>
parents:
2766
diff
changeset
|
37 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
39 if (len == 0) { |
461 | 40 return ngx_snprintf(errstr, size, |
2740
e5a4be07c3eb
axe incomplete support of Winsock error descriptions on NT
Igor Sysoev <igor@sysoev.ru>
parents:
2739
diff
changeset
|
41 "FormatMessage() error:(%d)", GetLastError()); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
42 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
43 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 /* remove ".\r\n\0" */ |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 while (errstr[len] == '\0' || errstr[len] == CR |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 || errstr[len] == LF || errstr[len] == '.') |
461 | 47 { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
48 --len; |
461 | 49 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
50 |
461 | 51 return &errstr[++len]; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
52 } |
3787
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
53 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
54 |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
55 ngx_uint_t |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
56 ngx_strerror_init(void) |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
57 { |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
58 return NGX_OK; |
e294f37401c0
use copied strerror() messages and autoconfigured sys_nerr value
Igor Sysoev <igor@sysoev.ru>
parents:
2770
diff
changeset
|
59 } |