Mercurial > hg > nginx-vendor-1-0
comparison src/http/ngx_http_variables.c @ 190:3689cd4e3228 NGINX_0_3_42
nginx 0.3.42
*) Feature: the "bind" option of the "listen" directive in IMAP/POP3
proxy.
*) Bugfix: if the same capture in the "rewrite" directive was used more
then once.
*) Bugfix: the $sent_http_content_type, $sent_http_content_length,
$sent_http_last_modified, $sent_http_connection,
$sent_http_keep_alive, and $sent_http_transfer_encoding variables
were not written to access log.
*) Bugfix: the $sent_http_cache_control returned value of the single
"Cache-Control" response header line.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Wed, 26 Apr 2006 00:00:00 +0400 |
parents | 54aabf2b0bc6 |
children | 8759b346e431 |
comparison
equal
deleted
inserted
replaced
189:fca7768a4aca | 190:3689cd4e3228 |
---|---|
45 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, | 45 static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, |
46 ngx_http_variable_value_t *v, uintptr_t data); | 46 ngx_http_variable_value_t *v, uintptr_t data); |
47 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, | 47 static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r, |
48 ngx_http_variable_value_t *v, uintptr_t data); | 48 ngx_http_variable_value_t *v, uintptr_t data); |
49 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, | 49 static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r, |
50 ngx_http_variable_value_t *v, uintptr_t data); | |
51 | |
52 static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r, | |
53 ngx_http_variable_value_t *v, uintptr_t data); | |
54 static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
55 ngx_http_variable_value_t *v, uintptr_t data); | |
56 static ngx_int_t ngx_http_variable_sent_last_modified(ngx_http_request_t *r, | |
57 ngx_http_variable_value_t *v, uintptr_t data); | |
58 static ngx_int_t ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
59 ngx_http_variable_value_t *v, uintptr_t data); | |
60 static ngx_int_t ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
61 ngx_http_variable_value_t *v, uintptr_t data); | |
62 static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
50 ngx_http_variable_value_t *v, uintptr_t data); | 63 ngx_http_variable_value_t *v, uintptr_t data); |
51 | 64 |
52 | 65 |
53 /* | 66 /* |
54 * TODO: | 67 * TODO: |
57 * SERVER_SOFTWARE | 70 * SERVER_SOFTWARE |
58 * | 71 * |
59 * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner) | 72 * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner) |
60 */ | 73 */ |
61 | 74 |
75 /* | |
76 * the $http_host, $http_user_agent, $http_referer, $http_via, | |
77 * and $http_x_forwarded_for variables may be handled by generic | |
78 * ngx_http_variable_unknown_header_in(), but for perfomance reasons | |
79 * they are handled using dedicated entries | |
80 */ | |
81 | |
62 static ngx_http_variable_t ngx_http_core_variables[] = { | 82 static ngx_http_variable_t ngx_http_core_variables[] = { |
63 | 83 |
64 { ngx_string("http_host"), NULL, ngx_http_variable_header, | 84 { ngx_string("http_host"), NULL, ngx_http_variable_header, |
65 offsetof(ngx_http_request_t, headers_in.host), 0, 0 }, | 85 offsetof(ngx_http_request_t, headers_in.host), 0, 0 }, |
66 | 86 |
143 0, 0, 0 }, | 163 0, 0, 0 }, |
144 | 164 |
145 { ngx_string("request_completion"), NULL, | 165 { ngx_string("request_completion"), NULL, |
146 ngx_http_variable_request_completion, | 166 ngx_http_variable_request_completion, |
147 0, 0, 0 }, | 167 0, 0, 0 }, |
168 | |
169 { ngx_string("sent_http_content_type"), NULL, | |
170 ngx_http_variable_sent_content_type, 0, 0, 0 }, | |
171 | |
172 { ngx_string("sent_http_content_length"), NULL, | |
173 ngx_http_variable_sent_content_length, 0, 0, 0 }, | |
174 | |
175 { ngx_string("sent_http_last_modified"), NULL, | |
176 ngx_http_variable_sent_last_modified, 0, 0, 0 }, | |
177 | |
178 { ngx_string("sent_http_connection"), NULL, | |
179 ngx_http_variable_sent_connection, 0, 0, 0 }, | |
180 | |
181 { ngx_string("sent_http_keep_alive"), NULL, | |
182 ngx_http_variable_sent_keep_alive, 0, 0, 0 }, | |
183 | |
184 { ngx_string("sent_http_transfer_encoding"), NULL, | |
185 ngx_http_variable_sent_transfer_encoding, 0, 0, 0 }, | |
186 | |
187 { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_headers, | |
188 offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 }, | |
148 | 189 |
149 { ngx_string("limit_rate"), ngx_http_variable_request_set_size, | 190 { ngx_string("limit_rate"), ngx_http_variable_request_set_size, |
150 ngx_http_variable_request, | 191 ngx_http_variable_request, |
151 offsetof(ngx_http_request_t, limit_rate), | 192 offsetof(ngx_http_request_t, limit_rate), |
152 NGX_HTTP_VAR_CHANGABLE|NGX_HTTP_VAR_NOCACHABLE, 0 }, | 193 NGX_HTTP_VAR_CHANGABLE|NGX_HTTP_VAR_NOCACHABLE, 0 }, |
845 return NGX_OK; | 886 return NGX_OK; |
846 } | 887 } |
847 | 888 |
848 | 889 |
849 static ngx_int_t | 890 static ngx_int_t |
891 ngx_http_variable_sent_content_type(ngx_http_request_t *r, | |
892 ngx_http_variable_value_t *v, uintptr_t data) | |
893 { | |
894 if (r->headers_out.content_type.len) { | |
895 v->len = r->headers_out.content_type.len; | |
896 v->valid = 1; | |
897 v->no_cachable = 0; | |
898 v->not_found = 0; | |
899 v->data = r->headers_out.content_type.data; | |
900 | |
901 } else { | |
902 v->not_found = 1; | |
903 } | |
904 | |
905 return NGX_OK; | |
906 } | |
907 | |
908 | |
909 static ngx_int_t | |
910 ngx_http_variable_sent_content_length(ngx_http_request_t *r, | |
911 ngx_http_variable_value_t *v, uintptr_t data) | |
912 { | |
913 u_char *p; | |
914 | |
915 if (r->headers_out.content_length) { | |
916 v->len = r->headers_out.content_length->value.len; | |
917 v->valid = 1; | |
918 v->no_cachable = 0; | |
919 v->not_found = 0; | |
920 v->data = r->headers_out.content_length->value.data; | |
921 | |
922 return NGX_OK; | |
923 } | |
924 | |
925 if (r->headers_out.content_length_n >= 0) { | |
926 p = ngx_palloc(r->pool, NGX_OFF_T_LEN); | |
927 if (p == NULL) { | |
928 return NGX_ERROR; | |
929 } | |
930 | |
931 v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p; | |
932 v->valid = 1; | |
933 v->no_cachable = 0; | |
934 v->not_found = 0; | |
935 v->data = p; | |
936 | |
937 return NGX_OK; | |
938 } | |
939 | |
940 v->not_found = 1; | |
941 | |
942 return NGX_OK; | |
943 } | |
944 | |
945 | |
946 static ngx_int_t | |
947 ngx_http_variable_sent_last_modified(ngx_http_request_t *r, | |
948 ngx_http_variable_value_t *v, uintptr_t data) | |
949 { | |
950 u_char *p; | |
951 | |
952 if (r->headers_out.last_modified) { | |
953 v->len = r->headers_out.last_modified->value.len; | |
954 v->valid = 1; | |
955 v->no_cachable = 0; | |
956 v->not_found = 0; | |
957 v->data = r->headers_out.last_modified->value.data; | |
958 | |
959 return NGX_OK; | |
960 } | |
961 | |
962 if (r->headers_out.last_modified_time >= 0) { | |
963 p = ngx_palloc(r->pool, | |
964 sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT") - 1); | |
965 if (p == NULL) { | |
966 return NGX_ERROR; | |
967 } | |
968 | |
969 v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p; | |
970 v->valid = 1; | |
971 v->no_cachable = 0; | |
972 v->not_found = 0; | |
973 v->data = p; | |
974 | |
975 return NGX_OK; | |
976 } | |
977 | |
978 v->not_found = 1; | |
979 | |
980 return NGX_OK; | |
981 } | |
982 | |
983 | |
984 static ngx_int_t | |
985 ngx_http_variable_sent_connection(ngx_http_request_t *r, | |
986 ngx_http_variable_value_t *v, uintptr_t data) | |
987 { | |
988 size_t len; | |
989 char *p; | |
990 | |
991 if (r->keepalive) { | |
992 len = sizeof("keep-alive") - 1; | |
993 p = "keep-alive"; | |
994 | |
995 } else { | |
996 len = sizeof("close") - 1; | |
997 p = "close"; | |
998 } | |
999 | |
1000 v->len = len; | |
1001 v->valid = 1; | |
1002 v->no_cachable = 0; | |
1003 v->not_found = 0; | |
1004 v->data = (u_char *) p; | |
1005 | |
1006 return NGX_OK; | |
1007 } | |
1008 | |
1009 | |
1010 static ngx_int_t | |
1011 ngx_http_variable_sent_keep_alive(ngx_http_request_t *r, | |
1012 ngx_http_variable_value_t *v, uintptr_t data) | |
1013 { | |
1014 u_char *p; | |
1015 ngx_http_core_loc_conf_t *clcf; | |
1016 | |
1017 if (r->keepalive) { | |
1018 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
1019 | |
1020 if (clcf->keepalive_header) { | |
1021 | |
1022 p = ngx_palloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN); | |
1023 if (p == NULL) { | |
1024 return NGX_ERROR; | |
1025 } | |
1026 | |
1027 v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p; | |
1028 v->valid = 1; | |
1029 v->no_cachable = 0; | |
1030 v->not_found = 0; | |
1031 v->data = p; | |
1032 | |
1033 return NGX_OK; | |
1034 } | |
1035 } | |
1036 | |
1037 v->not_found = 1; | |
1038 | |
1039 return NGX_OK; | |
1040 } | |
1041 | |
1042 | |
1043 static ngx_int_t | |
1044 ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r, | |
1045 ngx_http_variable_value_t *v, uintptr_t data) | |
1046 { | |
1047 if (r->chunked) { | |
1048 v->len = sizeof("chunked") - 1; | |
1049 v->valid = 1; | |
1050 v->no_cachable = 0; | |
1051 v->not_found = 0; | |
1052 v->data = (u_char *) "chunked"; | |
1053 | |
1054 } else { | |
1055 v->not_found = 1; | |
1056 } | |
1057 | |
1058 return NGX_OK; | |
1059 } | |
1060 | |
1061 | |
1062 static ngx_int_t | |
850 ngx_http_variable_request_completion(ngx_http_request_t *r, | 1063 ngx_http_variable_request_completion(ngx_http_request_t *r, |
851 ngx_http_variable_value_t *v, uintptr_t data) | 1064 ngx_http_variable_value_t *v, uintptr_t data) |
852 { | 1065 { |
853 if (r->request_complete) { | 1066 if (r->request_complete) { |
854 v->len = 2; | 1067 v->len = 2; |