Update and clean Tomato RAF files
[tomato.git] / release / src / router / nginx / src / http / ngx_http_postpone_filter_module.c
blob85c4b84d027200c68d0014634f7efbf0a0bcfd00
2 /*
3 * Copyright (C) Igor Sysoev
4 * Copyright (C) Nginx, Inc.
5 */
8 #include <ngx_config.h>
9 #include <ngx_core.h>
10 #include <ngx_http.h>
13 static ngx_int_t ngx_http_postpone_filter_add(ngx_http_request_t *r,
14 ngx_chain_t *in);
15 static ngx_int_t ngx_http_postpone_filter_init(ngx_conf_t *cf);
18 static ngx_http_module_t ngx_http_postpone_filter_module_ctx = {
19 NULL, /* preconfiguration */
20 ngx_http_postpone_filter_init, /* postconfiguration */
22 NULL, /* create main configuration */
23 NULL, /* init main configuration */
25 NULL, /* create server configuration */
26 NULL, /* merge server configuration */
28 NULL, /* create location configuration */
29 NULL /* merge location configuration */
33 ngx_module_t ngx_http_postpone_filter_module = {
34 NGX_MODULE_V1,
35 &ngx_http_postpone_filter_module_ctx, /* module context */
36 NULL, /* module directives */
37 NGX_HTTP_MODULE, /* module type */
38 NULL, /* init master */
39 NULL, /* init module */
40 NULL, /* init process */
41 NULL, /* init thread */
42 NULL, /* exit thread */
43 NULL, /* exit process */
44 NULL, /* exit master */
45 NGX_MODULE_V1_PADDING
49 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
52 static ngx_int_t
53 ngx_http_postpone_filter(ngx_http_request_t *r, ngx_chain_t *in)
55 ngx_connection_t *c;
56 ngx_http_postponed_request_t *pr;
58 c = r->connection;
60 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
61 "http postpone filter \"%V?%V\" %p", &r->uri, &r->args, in);
63 if (r != c->data) {
65 if (in) {
66 ngx_http_postpone_filter_add(r, in);
67 return NGX_OK;
70 #if 0
71 /* TODO: SSI may pass NULL */
72 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
73 "http postpone filter NULL inactive request",
74 &r->uri, &r->args);
75 #endif
77 return NGX_OK;
80 if (r->postponed == NULL) {
82 if (in || c->buffered) {
83 return ngx_http_next_body_filter(r->main, in);
86 return NGX_OK;
89 if (in) {
90 ngx_http_postpone_filter_add(r, in);
93 do {
94 pr = r->postponed;
96 if (pr->request) {
98 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
99 "http postpone filter wake \"%V?%V\"",
100 &pr->request->uri, &pr->request->args);
102 r->postponed = pr->next;
104 c->data = pr->request;
106 return ngx_http_post_request(pr->request, NULL);
109 if (pr->out == NULL) {
110 ngx_log_error(NGX_LOG_ALERT, c->log, 0,
111 "http postpone filter NULL output",
112 &r->uri, &r->args);
114 } else {
115 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
116 "http postpone filter output \"%V?%V\"",
117 &r->uri, &r->args);
119 if (ngx_http_next_body_filter(r->main, pr->out) == NGX_ERROR) {
120 return NGX_ERROR;
124 r->postponed = pr->next;
126 } while (r->postponed);
128 return NGX_OK;
132 static ngx_int_t
133 ngx_http_postpone_filter_add(ngx_http_request_t *r, ngx_chain_t *in)
135 ngx_http_postponed_request_t *pr, **ppr;
137 if (r->postponed) {
138 for (pr = r->postponed; pr->next; pr = pr->next) { /* void */ }
140 if (pr->request == NULL) {
141 goto found;
144 ppr = &pr->next;
146 } else {
147 ppr = &r->postponed;
150 pr = ngx_palloc(r->pool, sizeof(ngx_http_postponed_request_t));
151 if (pr == NULL) {
152 return NGX_ERROR;
155 *ppr = pr;
157 pr->request = NULL;
158 pr->out = NULL;
159 pr->next = NULL;
161 found:
163 if (ngx_chain_add_copy(r->pool, &pr->out, in) == NGX_OK) {
164 return NGX_OK;
167 return NGX_ERROR;
171 static ngx_int_t
172 ngx_http_postpone_filter_init(ngx_conf_t *cf)
174 ngx_http_next_body_filter = ngx_http_top_body_filter;
175 ngx_http_top_body_filter = ngx_http_postpone_filter;
177 return NGX_OK;