comparison src/http/modules/ngx_http_static_handler.c @ 24:77c7629a2627

nginx-0.0.1-2002-12-10-21:05:12 import
author Igor Sysoev <igor@sysoev.ru>
date Tue, 10 Dec 2002 18:05:12 +0000
parents d7908993fdeb
children 53cb81681040
comparison
equal deleted inserted replaced
23:f540a63026c9 24:77c7629a2627
38 38
39 ngx_http_discard_body(r); 39 ngx_http_discard_body(r);
40 ctx = r->connection->log->data; 40 ctx = r->connection->log->data;
41 ctx->action = "sending response"; 41 ctx->action = "sending response";
42 42
43 r->fd = ngx_open_file(r->filename, NGX_FILE_RDONLY); 43 if (r->fd != -1)
44 r->fd = ngx_open_file(r->filename.data, NGX_FILE_RDONLY);
45
44 if (r->fd == -1) { 46 if (r->fd == -1) {
45 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, 47 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
46 "ngx_http_static_handler: " 48 "ngx_http_static_handler: "
47 ngx_open_file_n " %s failed", r->filename); 49 ngx_open_file_n " %s failed", r->filename.data);
48 50
49 return NGX_HTTP_INTERNAL_SERVER_ERROR; 51 return NGX_HTTP_INTERNAL_SERVER_ERROR;
50 } 52 }
51 53
52 if (ngx_stat_fd(r->fd, &r->fileinfo) == -1) { 54 if (ngx_stat_fd(r->fd, &r->fileinfo) == -1) {
53 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno, 55 ngx_log_error(NGX_LOG_ERR, r->connection->log, ngx_errno,
54 "ngx_http_static_handler: " 56 "ngx_http_static_handler: "
55 ngx_stat_fd_n " %s failed", r->filename); 57 ngx_stat_fd_n " %s failed", r->filename.data);
56 58
57 /* close fd */ 59 /* close fd */
58 return NGX_HTTP_INTERNAL_SERVER_ERROR; 60 return NGX_HTTP_INTERNAL_SERVER_ERROR;
59 } 61 }
60 62
62 r->headers_out.content_length = ngx_file_size(r->fileinfo); 64 r->headers_out.content_length = ngx_file_size(r->fileinfo);
63 /* 65 /*
64 r->headers_out.last_modified = ngx_file_mtime(r->fileinfo); 66 r->headers_out.last_modified = ngx_file_mtime(r->fileinfo);
65 */ 67 */
66 68
69 ngx_test_null(r->headers_out.content_type,
70 ngx_push_table(r->headers_out.headers),
71 NGX_HTTP_INTERNAL_SERVER_ERROR);
72 r->headers_out.content_type->key.len = 12;
73 r->headers_out.content_type->key.data = "Content-Type";
74
67 /* STUB */ 75 /* STUB */
68 if (r->exten) { 76 if (r->exten.len) {
69 if (strcasecmp(r->exten, "html") == 0) 77 if (strcasecmp(r->exten.data, "html") == 0) {
70 r->headers_out.content_type = "text/html; charset=koi8-r"; 78 r->headers_out.content_type->value.len = 25;
71 else if (strcasecmp(r->exten, "gif") == 0) 79 r->headers_out.content_type->value.data =
72 r->headers_out.content_type = "image/gif"; 80 "text/html; charset=koi8-r";
73 else if (strcasecmp(r->exten, "jpg") == 0) 81 } else if (strcasecmp(r->exten.data, "gif") == 0) {
74 r->headers_out.content_type = "image/jpeg"; 82 r->headers_out.content_type->value.len = 9;
75 else if (strcasecmp(r->exten, "pdf") == 0) 83 r->headers_out.content_type->value.data = "image/gif";
76 r->headers_out.content_type = "application/pdf"; 84 } else if (strcasecmp(r->exten.data, "jpg") == 0) {
85 r->headers_out.content_type->value.len = 10;
86 r->headers_out.content_type->value.data = "image/jpeg";
87 }
77 88
78 } else { 89 } else {
79 r->headers_out.content_type = "text/html; charset=koi8-r"; 90 r->headers_out.content_type->value.len = 25;
91 r->headers_out.content_type->value.data = "text/html; charset=koi8-r";
80 } 92 }
81 93
82 /* STUB */ 94 /* STUB */
83 rc = ngx_http_header_filter(r); 95 rc = ngx_http_header_filter(r);
84 /* 96 /*
85 rc = ngx_send_http_header(r->headers_out); 97 rc = ngx_send_http_header(r);
86 */ 98 */
87 if (r->header_only) 99 if (r->header_only)
88 return rc; 100 return rc;
89 101
90 /* TODO: NGX_HTTP_INTERNAL_SERVER_ERROR is too late */ 102 /* TODO: NGX_HTTP_INTERNAL_SERVER_ERROR is too late */