static ngx_int_t 
ngx_http_minify_buf_in_memory(ngx_buf_t *buf,ngx_http_request_t *r)
{
    ngx_buf_t   *b = NULL, *dst = NULL, *min_dst = NULL;
    ngx_int_t size;

    size = buf->end - buf->start;

    dst = buf;
    dst->end[0] = 0;
    
    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }
    
    b->start = ngx_palloc(r->pool, size);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size;
    b->temporary = 1;
    
    min_dst = b;
    if (ngx_strcmp(r->headers_out.content_type.data,
                   ngx_http_minify_default_types[0].data) 
        == 0)
    {
        jsmin(dst,min_dst);

    } else if (ngx_strcmp(r->headers_out.content_type.data, 
                          ngx_http_minify_default_types[1].data) 
               == 0)
    {
        cssmin(dst,min_dst);

    } else {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    buf->start = min_dst->start;     
    buf->pos = min_dst->pos;
    buf->last = min_dst->last;
    buf->end = min_dst->end;
    buf->memory = 1;
    buf->in_file = 0;
    

    return NGX_OK;

}
示例#2
0
/* main -- Output any command line arguments as comments
        and then minify the input.
*/
extern int
main(int argc, char* argv[])
{
    cssmin();
    return 0;
}
static ngx_int_t 
ngx_http_minify_buf(ngx_buf_t *buf,ngx_http_request_t *r,
                    ngx_open_file_info_t *of)
{
    ngx_buf_t   *b = NULL, *dst = NULL, *min_dst = NULL;
    ngx_int_t    size;
    ngx_file_t  *src_file ;
    ssize_t n;

    src_file =  ngx_pcalloc(r->pool, sizeof(ngx_file_t));
    if (src_file == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    src_file->fd = of->fd;
    src_file->name = buf->file->name;
    src_file->log = r->connection->log;
    src_file->directio = of->is_directio;

    size = of->size;

    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    b->start = ngx_palloc(r->pool, size+1);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size ;
    b->temporary = 1;

    dst = b;

    #if (NGX_HAVE_FILE_AIO)
    
         ngx_output_chain_ctx_t       *ctx;
         ctx = ngx_http_get_module_ctx(r, ngx_http_minify_filter_module);
         if (ctx->aio_handler) {
             n = ngx_file_aio_read(src_file, dst->pos, (size_t) size, 0, 
                                   ctx->pool);

             if (n == NGX_AGAIN) {
             ctx->aio_handler(ctx, src_file);
             return NGX_AGAIN;
             }
    
         } else {
             n = ngx_read_file(src_file, dst->pos, (size_t) size, 0);
         }
    #else
    
        ngx_read_file(src_file, dst->pos, (size_t) size, 0);
    #endif

    dst->end[0] = 0;
    
    b = ngx_calloc_buf(r->pool); 
    if (b == NULL) {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }
    
    b->start = ngx_palloc(r->pool, size);
    b->pos = b->start;
    b->last = b->start;
    b->end = b->last + size;
    b->temporary = 1;
    
    min_dst = b;
    if (ngx_strcmp(r->headers_out.content_type.data,
                   ngx_http_minify_default_types[0].data) 
        == 0)
    {
        jsmin(dst,min_dst);

    } else if (ngx_strcmp(r->headers_out.content_type.data, 
                          ngx_http_minify_default_types[1].data) 
               == 0)
    {
        cssmin(dst,min_dst);

    } else {
        return NGX_HTTP_INTERNAL_SERVER_ERROR;
    }

    buf->start = min_dst->start;     
    buf->pos = min_dst->pos;
    buf->last = min_dst->last;
    buf->end = min_dst->end;
    buf->memory = 1;
    buf->in_file = 0;
    

    return NGX_OK;

}