Mercurial > hg > nginx-ranges
comparison src/http/modules/ngx_http_range_filter_module.c @ 391:1d9bef53cd8e
Range filter: late_ranges functionality.
Add one more filtering point after postpone filter. This allows to serve
range capable replies with subrequests. It's not as efficient as range
filtering for static data (i.e. doesn't save us from reading data from
disk if some filter needs them in memory), but it may save some network
bandwidth for us and for our users.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 21 Jul 2008 05:33:01 +0400 |
parents | a5f67d82aea3 |
children | 77df96611112 |
comparison
equal
deleted
inserted
replaced
390:a5f67d82aea3 | 391:1d9bef53cd8e |
---|---|
58 } ngx_http_range_filter_ctx_t; | 58 } ngx_http_range_filter_ctx_t; |
59 | 59 |
60 | 60 |
61 static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf); | 61 static ngx_int_t ngx_http_range_header_filter_init(ngx_conf_t *cf); |
62 static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf); | 62 static ngx_int_t ngx_http_range_body_filter_init(ngx_conf_t *cf); |
63 static ngx_int_t ngx_http_range_late_filter_init(ngx_conf_t *cf); | |
63 | 64 |
64 | 65 |
65 static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { | 66 static ngx_http_module_t ngx_http_range_header_filter_module_ctx = { |
66 NULL, /* preconfiguration */ | 67 NULL, /* preconfiguration */ |
67 ngx_http_range_header_filter_init, /* postconfiguration */ | 68 ngx_http_range_header_filter_init, /* postconfiguration */ |
122 NULL, /* exit master */ | 123 NULL, /* exit master */ |
123 NGX_MODULE_V1_PADDING | 124 NGX_MODULE_V1_PADDING |
124 }; | 125 }; |
125 | 126 |
126 | 127 |
128 static ngx_http_module_t ngx_http_range_late_filter_module_ctx = { | |
129 NULL, /* preconfiguration */ | |
130 ngx_http_range_late_filter_init, /* postconfiguration */ | |
131 | |
132 NULL, /* create main configuration */ | |
133 NULL, /* init main configuration */ | |
134 | |
135 NULL, /* create server configuration */ | |
136 NULL, /* merge server configuration */ | |
137 | |
138 NULL, /* create location configuration */ | |
139 NULL, /* merge location configuration */ | |
140 }; | |
141 | |
142 | |
143 ngx_module_t ngx_http_range_late_filter_module = { | |
144 NGX_MODULE_V1, | |
145 &ngx_http_range_late_filter_module_ctx, /* module context */ | |
146 NULL, /* module directives */ | |
147 NGX_HTTP_MODULE, /* module type */ | |
148 NULL, /* init master */ | |
149 NULL, /* init module */ | |
150 NULL, /* init process */ | |
151 NULL, /* init thread */ | |
152 NULL, /* exit thread */ | |
153 NULL, /* exit process */ | |
154 NULL, /* exit master */ | |
155 NGX_MODULE_V1_PADDING | |
156 }; | |
157 | |
158 | |
127 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; | 159 static ngx_http_output_header_filter_pt ngx_http_next_header_filter; |
128 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; | 160 static ngx_http_output_body_filter_pt ngx_http_next_body_early_filter; |
161 static ngx_http_output_body_filter_pt ngx_http_next_body_late_filter; | |
129 | 162 |
130 | 163 |
131 static ngx_int_t | 164 static ngx_int_t |
132 ngx_http_range_header_filter(ngx_http_request_t *r) | 165 ngx_http_range_header_filter(ngx_http_request_t *r) |
133 { | 166 { |
482 return ngx_http_next_header_filter(r); | 515 return ngx_http_next_header_filter(r); |
483 } | 516 } |
484 | 517 |
485 | 518 |
486 static ngx_int_t | 519 static ngx_int_t |
487 ngx_http_range_body_filter(ngx_http_request_t *r, ngx_chain_t *in) | 520 ngx_http_range_body_generic_filter(ngx_http_request_t *r, ngx_chain_t *in, |
521 ngx_http_output_body_filter_pt ngx_http_next_body_filter) | |
488 { | 522 { |
489 off_t start, last; | 523 off_t start, last; |
490 ngx_buf_t *b, *buf; | 524 ngx_buf_t *b, *buf; |
491 ngx_uint_t i; | 525 ngx_uint_t i; |
492 ngx_chain_t *out, *cl, *hcl, *rcl, *dcl, **ll; | 526 ngx_chain_t *out, *cl, *hcl, *rcl, *dcl, **ll; |
739 return NGX_ERROR; | 773 return NGX_ERROR; |
740 } | 774 } |
741 | 775 |
742 | 776 |
743 static ngx_int_t | 777 static ngx_int_t |
778 ngx_http_range_body_early_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
779 { | |
780 if (!r->allow_ranges || r->late_ranges) { | |
781 return ngx_http_next_body_early_filter(r, in); | |
782 } | |
783 | |
784 return ngx_http_range_body_generic_filter(r, in, | |
785 ngx_http_next_body_early_filter); | |
786 } | |
787 | |
788 | |
789 static ngx_int_t | |
790 ngx_http_range_body_late_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
791 { | |
792 if (!r->allow_ranges || !r->late_ranges) { | |
793 return ngx_http_next_body_late_filter(r, in); | |
794 } | |
795 | |
796 return ngx_http_range_body_generic_filter(r, in, | |
797 ngx_http_next_body_late_filter); | |
798 } | |
799 | |
800 | |
801 static ngx_int_t | |
744 ngx_http_range_header_filter_init(ngx_conf_t *cf) | 802 ngx_http_range_header_filter_init(ngx_conf_t *cf) |
745 { | 803 { |
746 ngx_http_next_header_filter = ngx_http_top_header_filter; | 804 ngx_http_next_header_filter = ngx_http_top_header_filter; |
747 ngx_http_top_header_filter = ngx_http_range_header_filter; | 805 ngx_http_top_header_filter = ngx_http_range_header_filter; |
748 | 806 |
751 | 809 |
752 | 810 |
753 static ngx_int_t | 811 static ngx_int_t |
754 ngx_http_range_body_filter_init(ngx_conf_t *cf) | 812 ngx_http_range_body_filter_init(ngx_conf_t *cf) |
755 { | 813 { |
756 ngx_http_next_body_filter = ngx_http_top_body_filter; | 814 ngx_http_next_body_early_filter = ngx_http_top_body_filter; |
757 ngx_http_top_body_filter = ngx_http_range_body_filter; | 815 ngx_http_top_body_filter = ngx_http_range_body_early_filter; |
758 | 816 |
759 return NGX_OK; | 817 return NGX_OK; |
760 } | 818 } |
819 | |
820 | |
821 static ngx_int_t | |
822 ngx_http_range_late_filter_init(ngx_conf_t *cf) | |
823 { | |
824 ngx_http_next_body_late_filter = ngx_http_top_body_filter; | |
825 ngx_http_top_body_filter = ngx_http_range_body_late_filter; | |
826 | |
827 return NGX_OK; | |
828 } |