Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.11 ]​[ nginx-1.14.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 #include <ngx_config.h>
0008 #include <ngx_core.h>
0009 #include <ngx_http.h>
0010 
0011 
0012 static char *ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd,
0013     void *conf);
0014 
0015 static ngx_command_t  ngx_http_empty_gif_commands[] = {
0016 
0017     { ngx_string("empty_gif"),
0018       NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
0019       ngx_http_empty_gif,
0020       0,
0021       0,
0022       NULL },
0023 
0024       ngx_null_command
0025 };
0026 
0027 
0028 /* the minimal single pixel transparent GIF, 43 bytes */
0029 
0030 static u_char  ngx_empty_gif[] = {
0031 
0032     'G', 'I', 'F', '8', '9', 'a',  /* header                                 */
0033 
0034                                    /* logical screen descriptor              */
0035     0x01, 0x00,                    /* logical screen width                   */
0036     0x01, 0x00,                    /* logical screen height                  */
0037     0x80,                          /* global 1-bit color table               */
0038     0x01,                          /* background color #1                    */
0039     0x00,                          /* no aspect ratio                        */
0040 
0041                                    /* global color table                     */
0042     0x00, 0x00, 0x00,              /* #0: black                              */
0043     0xff, 0xff, 0xff,              /* #1: white                              */
0044 
0045                                    /* graphic control extension              */
0046     0x21,                          /* extension introducer                   */
0047     0xf9,                          /* graphic control label                  */
0048     0x04,                          /* block size                             */
0049     0x01,                          /* transparent color is given,            */
0050                                    /*     no disposal specified,             */
0051                                    /*     user input is not expected         */
0052     0x00, 0x00,                    /* delay time                             */
0053     0x01,                          /* transparent color #1                   */
0054     0x00,                          /* block terminator                       */
0055 
0056                                    /* image descriptor                       */
0057     0x2c,                          /* image separator                        */
0058     0x00, 0x00,                    /* image left position                    */
0059     0x00, 0x00,                    /* image top position                     */
0060     0x01, 0x00,                    /* image width                            */
0061     0x01, 0x00,                    /* image height                           */
0062     0x00,                          /* no local color table, no interlaced    */
0063 
0064                                    /* table based image data                 */
0065     0x02,                          /* LZW minimum code size,                 */
0066                                    /*     must be at least 2-bit             */
0067     0x02,                          /* block size                             */
0068     0x4c, 0x01,                    /* compressed bytes 01_001_100, 0000000_1 */
0069                                    /* 100: clear code                        */
0070                                    /* 001: 1                                 */
0071                                    /* 101: end of information code           */
0072     0x00,                          /* block terminator                       */
0073 
0074     0x3B                           /* trailer                                */
0075 };
0076 
0077 
0078 static ngx_http_module_t  ngx_http_empty_gif_module_ctx = {
0079     NULL,                          /* preconfiguration */
0080     NULL,                          /* postconfiguration */
0081 
0082     NULL,                          /* create main configuration */
0083     NULL,                          /* init main configuration */
0084 
0085     NULL,                          /* create server configuration */
0086     NULL,                          /* merge server configuration */
0087 
0088     NULL,                          /* create location configuration */
0089     NULL                           /* merge location configuration */
0090 };
0091 
0092 
0093 ngx_module_t  ngx_http_empty_gif_module = {
0094     NGX_MODULE_V1,
0095     &ngx_http_empty_gif_module_ctx, /* module context */
0096     ngx_http_empty_gif_commands,   /* module directives */
0097     NGX_HTTP_MODULE,               /* module type */
0098     NULL,                          /* init master */
0099     NULL,                          /* init module */
0100     NULL,                          /* init process */
0101     NULL,                          /* init thread */
0102     NULL,                          /* exit thread */
0103     NULL,                          /* exit process */
0104     NULL,                          /* exit master */
0105     NGX_MODULE_V1_PADDING
0106 };
0107 
0108 
0109 static ngx_str_t  ngx_http_gif_type = ngx_string("image/gif");
0110 
0111 
0112 static ngx_int_t
0113 ngx_http_empty_gif_handler(ngx_http_request_t *r)
0114 {
0115     ngx_http_complex_value_t  cv;
0116 
0117     if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
0118         return NGX_HTTP_NOT_ALLOWED;
0119     }
0120 
0121     ngx_memzero(&cv, sizeof(ngx_http_complex_value_t));
0122 
0123     cv.value.len = sizeof(ngx_empty_gif);
0124     cv.value.data = ngx_empty_gif;
0125     r->headers_out.last_modified_time = 23349600;
0126 
0127     return ngx_http_send_response(r, NGX_HTTP_OK, &ngx_http_gif_type, &cv);
0128 }
0129 
0130 
0131 static char *
0132 ngx_http_empty_gif(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
0133 {
0134     ngx_http_core_loc_conf_t  *clcf;
0135 
0136     clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
0137     clcf->handler = ngx_http_empty_gif_handler;
0138 
0139     return NGX_CONF_OK;
0140 }