Mercurial > hg > nginx-vendor-0-8
comparison src/http/modules/ngx_http_empty_gif_module.c @ 126:df17fbafec8f NGINX_0_3_10
nginx 0.3.10
*) Change: the "valid_referers" directive and the "$invalid_referer"
variable were moved to the new ngx_http_referer_module from the
ngx_http_rewrite_module.
*) Change: the "$apache_bytes_sent" variable name was changed to
"$body_bytes_sent".
*) Feature: the "$sent_http_..." variables.
*) Feature: the "if" directive supports the "=" and "!=" operations.
*) Feature: the "proxy_pass" directive supports the HTTPS protocol.
*) Feature: the "proxy_set_body" directive.
*) Feature: the "post_action" directive.
*) Feature: the ngx_http_empty_gif_module.
*) Feature: the "worker_cpu_affinity" directive for Linux.
*) Bugfix: the "rewrite" directive did not unescape URI part in
redirect, now it is unescaped except the %00-%25 and %7F-%FF
characters.
*) Bugfix: nginx could not be built by the icc 9.0 compiler.
*) Bugfix: if the SSI was enabled for zero size static file, then the
chunked response was encoded incorrectly.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Tue, 15 Nov 2005 00:00:00 +0300 |
parents | |
children | 82d695e3d662 |
comparison
equal
deleted
inserted
replaced
125:97504de1f89e | 126:df17fbafec8f |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 #include <ngx_config.h> | |
7 #include <ngx_core.h> | |
8 #include <ngx_http.h> | |
9 | |
10 | |
11 static char *ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, | |
12 void *conf); | |
13 | |
14 static ngx_command_t ngx_http_empty_gif_commands[] = { | |
15 | |
16 { ngx_string("empty_gif"), | |
17 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, | |
18 ngx_http_empty_gif, | |
19 0, | |
20 0, | |
21 NULL }, | |
22 | |
23 ngx_null_command | |
24 }; | |
25 | |
26 | |
27 /* the minimal single pixel transparent GIF, 43 bytes */ | |
28 | |
29 static u_char ngx_empty_gif[] = { | |
30 | |
31 'G', 'I', 'F', '8', '9', 'a', /* header */ | |
32 | |
33 /* logical screen descriptor */ | |
34 0x01, 0x00, /* logical screen width */ | |
35 0x01, 0x00, /* logical screen height */ | |
36 0x80, /* global 1-bit color table */ | |
37 0x01, /* background color #1 */ | |
38 0x00, /* no aspect ratio */ | |
39 | |
40 /* global color table */ | |
41 0x00, 0x00, 0x00, /* #0: black */ | |
42 0xff, 0xff, 0xff, /* #1: white */ | |
43 | |
44 /* graphic control extension */ | |
45 0x21, /* extension introducer */ | |
46 0xf9, /* graphic control label */ | |
47 0x04, /* block size */ | |
48 0x01, /* transparent color is given, */ | |
49 /* no disposal specified, */ | |
50 /* user input is not expected */ | |
51 0x00, 0x00, /* delay time */ | |
52 0x01, /* transparent color #1 */ | |
53 0x00, /* block terminator */ | |
54 | |
55 /* image descriptor */ | |
56 0x2c, /* image separator */ | |
57 0x00, 0x00, /* image left position */ | |
58 0x00, 0x00, /* image top position */ | |
59 0x01, 0x00, /* image width */ | |
60 0x01, 0x00, /* image height */ | |
61 0x00, /* no local color table, no interlaced */ | |
62 | |
63 /* table based image data */ | |
64 0x02, /* LZW minimum code size, */ | |
65 /* must be at least 2-bit */ | |
66 0x02, /* block size */ | |
67 0x4c, 0x01, /* compressed bytes 01_001_100, 0000000_1 */ | |
68 /* 100: clear code */ | |
69 /* 001: 1 */ | |
70 /* 101: end of information code */ | |
71 0x00, /* block terminator */ | |
72 | |
73 0x3B /* trailer */ | |
74 }; | |
75 | |
76 | |
77 ngx_http_module_t ngx_http_empty_gif_module_ctx = { | |
78 NULL, /* preconfiguration */ | |
79 NULL, /* postconfiguration */ | |
80 | |
81 NULL, /* create main configuration */ | |
82 NULL, /* init main configuration */ | |
83 | |
84 NULL, /* create server configuration */ | |
85 NULL, /* merge server configuration */ | |
86 | |
87 NULL, /* create location configuration */ | |
88 NULL /* merge location configuration */ | |
89 }; | |
90 | |
91 | |
92 ngx_module_t ngx_http_empty_gif_module = { | |
93 NGX_MODULE_V1, | |
94 &ngx_http_empty_gif_module_ctx, /* module context */ | |
95 ngx_http_empty_gif_commands, /* module directives */ | |
96 NGX_HTTP_MODULE, /* module type */ | |
97 NULL, /* init master */ | |
98 NULL, /* init module */ | |
99 NULL, /* init process */ | |
100 NULL, /* init thread */ | |
101 NULL, /* exit thread */ | |
102 NULL, /* exit process */ | |
103 NULL, /* exit master */ | |
104 NGX_MODULE_V1_PADDING | |
105 }; | |
106 | |
107 | |
108 static ngx_int_t | |
109 ngx_http_empty_gif_handler(ngx_http_request_t *r) | |
110 { | |
111 ngx_int_t rc; | |
112 ngx_buf_t *b; | |
113 ngx_chain_t out; | |
114 | |
115 if (r->method != NGX_HTTP_GET && r->method != NGX_HTTP_HEAD) { | |
116 return NGX_HTTP_NOT_ALLOWED; | |
117 } | |
118 | |
119 rc = ngx_http_discard_body(r); | |
120 | |
121 if (rc != NGX_OK && rc != NGX_AGAIN) { | |
122 return rc; | |
123 } | |
124 | |
125 r->headers_out.content_type.len = sizeof("image/gif") - 1; | |
126 r->headers_out.content_type.data = (u_char *) "image/gif"; | |
127 | |
128 if (r->method == NGX_HTTP_HEAD) { | |
129 r->headers_out.status = NGX_HTTP_OK; | |
130 | |
131 rc = ngx_http_send_header(r); | |
132 | |
133 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
134 return rc; | |
135 } | |
136 } | |
137 | |
138 b = ngx_create_temp_buf(r->pool, sizeof(ngx_empty_gif)); | |
139 if (b == NULL) { | |
140 return NGX_HTTP_INTERNAL_SERVER_ERROR; | |
141 } | |
142 | |
143 out.buf = b; | |
144 out.next = NULL; | |
145 | |
146 b->pos = ngx_empty_gif; | |
147 b->last = ngx_empty_gif + sizeof(ngx_empty_gif); | |
148 b->last_buf = 1; | |
149 | |
150 r->headers_out.status = NGX_HTTP_OK; | |
151 r->headers_out.content_length_n = b->last - b->pos; | |
152 r->headers_out.last_modified_time = 23349600; | |
153 | |
154 rc = ngx_http_send_header(r); | |
155 | |
156 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { | |
157 return rc; | |
158 } | |
159 | |
160 return ngx_http_output_filter(r, &out);; | |
161 } | |
162 | |
163 | |
164 static char * | |
165 ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
166 { | |
167 ngx_http_core_loc_conf_t *clcf; | |
168 | |
169 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
170 clcf->handler = ngx_http_empty_gif_handler; | |
171 | |
172 return NGX_CONF_OK; | |
173 } |