Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_static_handler.c @ 96:a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 27 May 2003 12:18:54 +0000 |
parents | 29bf798b583f |
children | a059e1aa65d4 |
comparison
equal
deleted
inserted
replaced
95:b48066122884 | 96:a23d010f356d |
---|---|
1 | 1 |
2 #include <ngx_config.h> | 2 #include <ngx_config.h> |
3 #include <ngx_core.h> | 3 #include <ngx_core.h> |
4 #include <ngx_string.h> | |
5 #include <ngx_file.h> | |
6 #include <ngx_hunk.h> | |
7 #include <ngx_http.h> | 4 #include <ngx_http.h> |
8 #include <ngx_http_config.h> | 5 #include <ngx_http_config.h> |
9 #include <ngx_http_core_module.h> | 6 #include <ngx_http_core_module.h> |
10 #include <ngx_http_output_filter.h> | 7 #include <ngx_http_output_filter.h> |
11 | 8 |
12 | 9 |
13 ngx_http_module_t ngx_http_static_module; | |
14 | |
15 | 10 |
16 int ngx_http_static_handler(ngx_http_request_t *r) | 11 int ngx_http_static_handler(ngx_http_request_t *r) |
17 { | 12 { |
18 int rc, key, i; | 13 int rc, key, i; |
19 ngx_log_e level; | 14 ngx_log_e level; |
20 ngx_err_t err; | 15 ngx_err_t err; |
21 ngx_hunk_t *h; | 16 ngx_hunk_t *h; |
22 ngx_http_type_t *type; | 17 ngx_http_type_t *type; |
23 ngx_http_log_ctx_t *ctx; | 18 ngx_http_log_ctx_t *ctx; |
24 ngx_http_core_loc_conf_t *core_lcf; | 19 ngx_http_core_loc_conf_t *clcf; |
25 | |
26 core_lcf = (ngx_http_core_loc_conf_t *) | |
27 ngx_http_get_module_loc_conf(r, ngx_http_core_module_ctx); | |
28 | |
29 #if 0 | |
30 ngx_http_event_static_handler_loc_conf_t *lcf; | |
31 | |
32 lcf = (ngx_http_event_static_handler_loc_conf_t *) | |
33 ngx_get_module_loc_conf(r, &ngx_http_event_static_handler_module_ctx); | |
34 | |
35 #endif | |
36 | 20 |
37 rc = ngx_http_discard_body(r); | 21 rc = ngx_http_discard_body(r); |
38 | 22 |
39 if (rc != NGX_OK) { | 23 if (rc != NGX_OK) { |
40 return rc; | 24 return rc; |
25 } | |
26 | |
27 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { | |
28 return NGX_HTTP_NOT_ALLOWED; | |
41 } | 29 } |
42 | 30 |
43 ctx = r->connection->log->data; | 31 ctx = r->connection->log->data; |
44 ctx->action = "sending response"; | 32 ctx->action = "sending response"; |
45 | 33 |
100 | 88 |
101 ngx_test_null(r->headers_out.content_type, | 89 ngx_test_null(r->headers_out.content_type, |
102 ngx_push_table(r->headers_out.headers), | 90 ngx_push_table(r->headers_out.headers), |
103 NGX_HTTP_INTERNAL_SERVER_ERROR); | 91 NGX_HTTP_INTERNAL_SERVER_ERROR); |
104 | 92 |
105 r->headers_out.content_type->key.len = 12; | 93 r->headers_out.content_type->key.len = 0; |
106 r->headers_out.content_type->key.data = "Content-Type"; | 94 r->headers_out.content_type->key.data = NULL; |
95 r->headers_out.content_type->value.len = 0; | |
96 r->headers_out.content_type->value.data = NULL; | |
97 | |
98 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
107 | 99 |
108 if (r->exten.len) { | 100 if (r->exten.len) { |
109 ngx_http_types_hash_key(key, r->exten); | 101 ngx_http_types_hash_key(key, r->exten); |
110 | 102 |
111 type = (ngx_http_type_t *) core_lcf->types[key].elts; | 103 type = (ngx_http_type_t *) clcf->types[key].elts; |
112 for (i = 0; i < core_lcf->types[key].nelts; i++) { | 104 for (i = 0; i < clcf->types[key].nelts; i++) { |
113 if (r->exten.len != type[i].exten.len) { | 105 if (r->exten.len != type[i].exten.len) { |
114 continue; | 106 continue; |
115 } | 107 } |
116 | 108 |
117 if (ngx_strcasecmp(r->exten.data, type[i].exten.data) == 0) { | 109 if (ngx_strcasecmp(r->exten.data, type[i].exten.data) == 0) { |
118 r->headers_out.content_type->value.len = type[i].type.len; | 110 r->headers_out.content_type->value.len = type[i].type.len; |
119 r->headers_out.content_type->value.data = type[i].type.data; | 111 r->headers_out.content_type->value.data = type[i].type.data; |
112 | |
113 break; | |
120 } | 114 } |
121 } | 115 } |
122 } | 116 } |
123 | 117 |
124 if (r->headers_out.content_type->value.len == 0) { | 118 if (r->headers_out.content_type->value.len == 0) { |
125 /* STUB: default type */ | 119 r->headers_out.content_type->value.len = clcf->default_type.len; |
126 r->headers_out.content_type->value.len = 25; | 120 r->headers_out.content_type->value.data = clcf->default_type.data; |
127 r->headers_out.content_type->value.data = "text/html; charset=koi8-r"; | |
128 } | 121 } |
129 | 122 |
130 /* we need to allocate all before the header would be sent */ | 123 /* we need to allocate all before the header would be sent */ |
131 ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), | 124 ngx_test_null(h, ngx_pcalloc(r->pool, sizeof(ngx_hunk_t)), |
132 NGX_HTTP_INTERNAL_SERVER_ERROR); | 125 NGX_HTTP_INTERNAL_SERVER_ERROR); |
133 | 126 |
134 ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), | 127 ngx_test_null(h->file, ngx_pcalloc(r->pool, sizeof(ngx_file_t)), |
135 NGX_HTTP_INTERNAL_SERVER_ERROR); | 128 NGX_HTTP_INTERNAL_SERVER_ERROR); |
136 | 129 |
137 ngx_http_send_header(r); | 130 |
138 if (r->header_only) | 131 rc = ngx_http_send_header(r); |
132 | |
133 if (r->header_only) { | |
134 if (rc == NGX_AGAIN) { | |
135 ngx_http_set_write_handler(r); | |
136 | |
137 } else { | |
138 ngx_http_finalize_request(r, 0); | |
139 } | |
140 | |
139 return NGX_OK; | 141 return NGX_OK; |
142 } | |
140 | 143 |
141 | 144 |
142 h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; | 145 h->type = NGX_HUNK_FILE|NGX_HUNK_LAST; |
143 h->file_pos = 0; | 146 h->file_pos = 0; |
144 h->file_last = ngx_file_size(r->file.info); | 147 h->file_last = ngx_file_size(r->file.info); |