⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ngx_http_fastcgi_module.c

📁 nginx 反向代理0.7.1版本 用于实现反向代理
💻 C
📖 第 1 页 / 共 5 页
字号:
            if (f->pos + f->padding == f->last) {                f->state = ngx_http_fastcgi_st_version;                break;            }            f->padding -= f->last - f->pos;            break;        }        /* f->state == ngx_http_fastcgi_st_data */        if (f->type == NGX_HTTP_FASTCGI_STDERR) {            if (f->length) {                if (f->pos == f->last) {                    break;                }                line.data = f->pos;                if (f->pos + f->length <= f->last) {                    line.len = f->length;                    f->pos += f->length;                    f->length = 0;                    f->state = ngx_http_fastcgi_st_padding;                } else {                    line.len = f->last - f->pos;                    f->length -= f->last - f->pos;                    f->pos = f->last;                }                while (line.data[line.len - 1] == LF                       || line.data[line.len - 1] == CR                       || line.data[line.len - 1] == '.'                       || line.data[line.len - 1] == ' ')                {                    line.len--;                }                ngx_log_error(NGX_LOG_ERR, p->log, 0,                              "FastCGI sent in stderr: \"%V\"", &line);                if (f->pos == f->last) {                    break;                }            } else {                f->state = ngx_http_fastcgi_st_version;            }            continue;        }        /* f->type == NGX_HTTP_FASTCGI_STDOUT */        if (f->pos == f->last) {            break;        }        if (p->free) {            b = p->free->buf;            p->free = p->free->next;        } else {            b = ngx_alloc_buf(p->pool);            if (b == NULL) {                return NGX_ERROR;            }        }        ngx_memzero(b, sizeof(ngx_buf_t));        b->pos = f->pos;        b->start = buf->start;        b->end = buf->end;        b->tag = p->tag;        b->temporary = 1;        b->recycled = 1;        *prev = b;        prev = &b->shadow;        cl = ngx_alloc_chain_link(p->pool);        if (cl == NULL) {            return NGX_ERROR;        }        cl->buf = b;        cl->next = NULL;        if (p->in) {            *p->last_in = cl;        } else {            p->in = cl;        }        p->last_in = &cl->next;        /* STUB */ b->num = buf->num;        ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,                       "input buf #%d %p", b->num, b->pos);        if (f->pos + f->length < f->last) {            if (f->padding) {                f->state = ngx_http_fastcgi_st_padding;            } else {                f->state = ngx_http_fastcgi_st_version;            }            f->pos += f->length;            b->last = f->pos;            continue;        }        if (f->pos + f->length == f->last) {            if (f->padding) {                f->state = ngx_http_fastcgi_st_padding;            } else {                f->state = ngx_http_fastcgi_st_version;            }            b->last = f->last;            break;        }        f->length -= f->last - f->pos;        b->last = f->last;        break;    }    if (b) {        b->shadow = buf;        b->last_shadow = 1;        ngx_log_debug2(NGX_LOG_DEBUG_EVENT, p->log, 0,                       "input buf %p %z", b->pos, b->last - b->pos);        return NGX_OK;    }    /* there is no data record in the buf, add it to free chain */    if (ngx_event_pipe_add_free_buf(p, buf) != NGX_OK) {        return NGX_ERROR;    }    return NGX_OK;}static ngx_int_tngx_http_fastcgi_process_record(ngx_http_request_t *r,    ngx_http_fastcgi_ctx_t *f){    u_char                     ch, *p;    ngx_http_fastcgi_state_e   state;    state = f->state;    for (p = f->pos; p < f->last; p++) {        ch = *p;        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                       "http fastcgi record byte: %02Xd", ch);        switch (state) {        case ngx_http_fastcgi_st_version:            if (ch != 1) {                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "upstream sent unsupported FastCGI "                              "protocol version: %d", ch);                return NGX_ERROR;            }            state = ngx_http_fastcgi_st_type;            break;        case ngx_http_fastcgi_st_type:            switch (ch) {            case NGX_HTTP_FASTCGI_STDOUT:            case NGX_HTTP_FASTCGI_STDERR:            case NGX_HTTP_FASTCGI_END_REQUEST:                 f->type = (ngx_uint_t) ch;                 break;            default:                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "upstream sent invalid FastCGI "                              "record type: %d", ch);                return NGX_ERROR;            }            state = ngx_http_fastcgi_st_request_id_hi;            break;        /* we support the single request per connection */        case ngx_http_fastcgi_st_request_id_hi:            if (ch != 0) {                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "upstream sent unexpected FastCGI "                              "request id high byte: %d", ch);                return NGX_ERROR;            }            state = ngx_http_fastcgi_st_request_id_lo;            break;        case ngx_http_fastcgi_st_request_id_lo:            if (ch != 1) {                ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,                              "upstream sent unexpected FastCGI "                              "request id low byte: %d", ch);                return NGX_ERROR;            }            state = ngx_http_fastcgi_st_content_length_hi;            break;        case ngx_http_fastcgi_st_content_length_hi:            f->length = ch << 8;            state = ngx_http_fastcgi_st_content_length_lo;            break;        case ngx_http_fastcgi_st_content_length_lo:            f->length |= (size_t) ch;            state = ngx_http_fastcgi_st_padding_length;            break;        case ngx_http_fastcgi_st_padding_length:            f->padding = (size_t) ch;            state = ngx_http_fastcgi_st_reserved;            break;        case ngx_http_fastcgi_st_reserved:            state = ngx_http_fastcgi_st_data;            ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                           "http fastcgi record length: %z", f->length);            f->pos = p + 1;            f->state = state;            return NGX_OK;        /* suppress warning */        case ngx_http_fastcgi_st_data:        case ngx_http_fastcgi_st_padding:            break;        }    }    f->state = state;    return NGX_AGAIN;}static voidngx_http_fastcgi_abort_request(ngx_http_request_t *r){    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "abort http fastcgi request");    return;}static voidngx_http_fastcgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc){    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,                   "finalize http fastcgi request");    return;}static ngx_int_tngx_http_fastcgi_add_variables(ngx_conf_t *cf){    ngx_http_variable_t  *var;    var = ngx_http_add_variable(cf, &ngx_http_fastcgi_script_name,                                NGX_HTTP_VAR_NOHASH|NGX_HTTP_VAR_NOCACHEABLE);    if (var == NULL) {        return NGX_ERROR;    }    var->get_handler = ngx_http_fastcgi_script_name_variable;    return NGX_OK;}static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf){    ngx_http_fastcgi_loc_conf_t  *conf;    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_fastcgi_loc_conf_t));    if (conf == NULL) {        return NGX_CONF_ERROR;    }    /*     * set by ngx_pcalloc():     *     *     conf->upstream.bufs.num = 0;     *     conf->upstream.next_upstream = 0;     *     conf->upstream.temp_path = NULL;     *     conf->upstream.hide_headers_hash = { NULL, 0 };     *     conf->upstream.schema = { 0, NULL };     *     conf->upstream.uri = { 0, NULL };     *     conf->upstream.location = NULL;     *     conf->upstream.store_lengths = NULL;     *     conf->upstream.store_values = NULL;     *     *     conf->index.len = 0;     *     conf->index.data = NULL;     */    conf->upstream.store = NGX_CONF_UNSET;    conf->upstream.store_access = NGX_CONF_UNSET_UINT;    conf->upstream.buffering = NGX_CONF_UNSET;    conf->upstream.ignore_client_abort = NGX_CONF_UNSET;    conf->upstream.connect_timeout = NGX_CONF_UNSET_MSEC;    conf->upstream.send_timeout = NGX_CONF_UNSET_MSEC;    conf->upstream.read_timeout = NGX_CONF_UNSET_MSEC;    conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;    conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;    conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;    conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;    conf->upstream.temp_file_write_size_conf = NGX_CONF_UNSET_SIZE;    conf->upstream.pass_request_headers = NGX_CONF_UNSET;    conf->upstream.pass_request_body = NGX_CONF_UNSET;    conf->upstream.hide_headers = NGX_CONF_UNSET_PTR;    conf->upstream.pass_headers = NGX_CONF_UNSET_PTR;    conf->upstream.intercept_errors = NGX_CONF_UNSET;    /* "fastcgi_cyclic_temp_file" is disabled */    conf->upstream.cyclic_temp_file = 0;    conf->catch_stderr = NGX_CONF_UNSET_PTR;    return conf;}static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child){    ngx_http_fastcgi_loc_conf_t *prev = parent;    ngx_http_fastcgi_loc_conf_t *conf = child;    u_char                       *p;    size_t                        size;    uintptr_t                    *code;    ngx_uint_t                    i;    ngx_keyval_t                 *src;    ngx_hash_init_t               hash;    ngx_http_script_compile_t     sc;    ngx_http_script_copy_code_t  *copy;    if (conf->upstream.store != 0) {        ngx_conf_merge_value(conf->upstream.store,                                  prev->upstream.store, 0);        if (conf->upstream.store_lengths == NULL) {            conf->upstream.store_lengths = prev->upstream.store_lengths;            conf->upstream.store_values = prev->upstream.store_values;        }    }    ngx_conf_merge_uint_value(conf->upstream.store_access,                              prev->upstream.store_access, 0600);    ngx_conf_merge_value(conf->upstream.buffering,                              prev->upstream.buffering, 1);    ngx_conf_merge_value(conf->upstream.ignore_client_abort,                              prev->upstream.ignore_client_abort, 0);    ngx_conf_merge_msec_value(conf->upstream.connect_timeout,                              prev->upstream.connect_timeout, 60000);    ngx_conf_merge_msec_value(conf->upstream.send_timeout,                              prev->upstream.send_timeout, 60000);    ngx_conf_merge_msec_value(conf->upstream.read_timeout,                              prev->upstream.read_timeout, 60000);    ngx_conf_merge_size_value(conf->upstream.send_lowat,                              prev->upstream.send_lowat, 0);    ngx_conf_merge_size_value(conf->upstream.buffer_size,                              prev->upstream.buffer_size,                              (size_t) ngx_pagesize);    ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,                              8, ngx_pagesize);    if (conf->upstream.bufs.num < 2) {        ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,                           "there must be at least 2 \"fastcgi_buffers\"");        return NGX_CONF_ERROR;    }    size = conf->upstream.buffer_size;    if (size < conf->upstream.bufs.size) {        size = conf->upstream.bufs.size;    }    ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -