src\http\ngx_http_core_module.c
void
ngx_http_update_location_config(ngx_http_request_t *r)
{
ngx_http_core_loc_conf_t *clcf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
if (r->method & clcf->limit_except) {
r->loc_conf = clcf->limit_except_loc_conf;
clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
}
if (r == r->main) {
ngx_set_connection_log(r->connection, clcf->error_log);
}
if ((ngx_io.flags & NGX_IO_SENDFILE) && clcf->sendfile) {
r->connection->sendfile = 1;
} else {
r->connection->sendfile = 0;
}
if (clcf->client_body_in_file_only) {
r->request_body_in_file_only = 1;
r->request_body_in_persistent_file = 1;
r->request_body_in_clean_file =
clcf->client_body_in_file_only == NGX_HTTP_REQUEST_BODY_FILE_CLEAN;
r->request_body_file_log_level = NGX_LOG_NOTICE;
} else {
r->request_body_file_log_level = NGX_LOG_WARN;
}
r->request_body_in_single_buf = clcf->client_body_in_single_buffer;
if (r->keepalive) {
if (clcf->keepalive_timeout == 0) {
r->keepalive = 0;
} else if (r->connection->requests >= clcf->keepalive_requests) {
r->keepalive = 0;
} else if (ngx_current_msec - r->connection->start_time
> clcf->keepalive_time)
{
r->keepalive = 0;
} else if (r->headers_in.msie6
&& r->method == NGX_HTTP_POST
&& (clcf->keepalive_disable
& NGX_HTTP_KEEPALIVE_DISABLE_MSIE6))
{
/*
* MSIE may wait for some time if an response for
* a POST request was sent over a keepalive connection
*/
r->keepalive = 0;
} else if (r->headers_in.safari
&& (clcf->keepalive_disable
& NGX_HTTP_KEEPALIVE_DISABLE_SAFARI))
{
/*
* Safari may send a POST request to a closed keepalive
* connection and may stall for some time, see
* https://bugs.webkit.org/show_bug.cgi?id=5760
*/
r->keepalive = 0;
}
}
if (!clcf->tcp_nopush) {
/* disable TCP_NOPUSH/TCP_CORK use */
r->connection->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
}
if (clcf->handler) {
r->content_handler = clcf->handler;
}
}
该函数接收一个 ngx_http_request_t 类型的指针作为参数,这个结构体包含了 HTTP 请求的所有相关信息。函数的主要工作是根据请求匹配到的 location 配置,更新请求的各种处理参数。
ngx_http_update_location_config 函数是 Nginx 请求处理流程中的关键环节,它负责将 location 配置中的各种参数应用到当前请求上。通过这个函数,Nginx 实现了:
根据 location 配置定制化请求处理行为
优化文件传输(sendfile)
控制请求体存储方式
管理 keepalive 连接
设置 TCP 层优化选项
指定自定义内容处理器
2208

被折叠的 条评论
为什么被折叠?



