comparison src/http/modules/ngx_http_range_filter.c @ 231:92db0aa1e83f

nginx-0.0.1-2004-01-16-21:29:15 import
author Igor Sysoev <igor@sysoev.ru>
date Fri, 16 Jan 2004 18:29:15 +0000
parents 8dee38ea9117
children 87e73f067470
comparison
equal deleted inserted replaced
230:1119faf4635a 231:92db0aa1e83f
75 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; 75 static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
76 76
77 77
78 static int ngx_http_range_header_filter(ngx_http_request_t *r) 78 static int ngx_http_range_header_filter(ngx_http_request_t *r)
79 { 79 {
80 int rc, boundary, len, i; 80 ngx_int_t rc, boundary, suffix, len, i;
81 char *p; 81 char *p;
82 off_t start, end; 82 off_t start, end;
83 ngx_http_range_t *range; 83 ngx_http_range_t *range;
84 ngx_http_range_filter_ctx_t *ctx; 84 ngx_http_range_filter_ctx_t *ctx;
85 85
119 rc = 0; 119 rc = 0;
120 range = NULL; 120 range = NULL;
121 p = r->headers_in.range->value.data + 6; 121 p = r->headers_in.range->value.data + 6;
122 122
123 for ( ;; ) { 123 for ( ;; ) {
124 start = end = 0; 124 start = 0;
125 end = 0;
126 suffix = 0;
125 127
126 while (*p == ' ') { p++; } 128 while (*p == ' ') { p++; }
129
130 if (*p != '-') {
131 if (*p < '0' || *p > '9') {
132 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
133 break;
134 }
135
136 while (*p >= '0' && *p <= '9') {
137 start = start * 10 + *p++ - '0';
138 }
139
140 while (*p == ' ') { p++; }
141
142 if (*p++ != '-') {
143 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
144 break;
145 }
146
147 if (start >= r->headers_out.content_length_n) {
148 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
149 break;
150 }
151
152 while (*p == ' ') { p++; }
153
154 if (*p == ',' || *p == '\0') {
155 ngx_test_null(range, ngx_push_array(&r->headers_out.ranges),
156 NGX_ERROR);
157 range->start = start;
158 range->end = r->headers_out.content_length_n;
159
160 if (*p++ != ',') {
161 break;
162 }
163
164 continue;
165 }
166
167 } else {
168 suffix = 1;
169 p++;
170 }
127 171
128 if (*p < '0' || *p > '9') { 172 if (*p < '0' || *p > '9') {
129 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE; 173 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
130 break; 174 break;
131 } 175 }
132 176
133 while (*p >= '0' && *p <= '9') { 177 while (*p >= '0' && *p <= '9') {
134 start = start * 10 + *p++ - '0';
135 }
136
137 while (*p == ' ') { p++; }
138
139 if (*p++ != '-') {
140 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
141 break;
142 }
143
144 if (start >= r->headers_out.content_length_n) {
145 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
146 break;
147 }
148
149 while (*p == ' ') { p++; }
150
151 if (*p == ',' || *p == '\0') {
152 ngx_test_null(range, ngx_push_array(&r->headers_out.ranges),
153 NGX_ERROR);
154 range->start = start;
155 range->end = r->headers_out.content_length_n;
156
157 if (*p++ == ',') {
158 continue;
159 }
160
161 break;
162 }
163
164 if (*p < '0' || *p > '9') {
165 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
166 break;
167 }
168
169 while (*p >= '0' && *p <= '9') {
170 end = end * 10 + *p++ - '0'; 178 end = end * 10 + *p++ - '0';
171 } 179 }
172 180
173 while (*p == ' ') { p++; } 181 while (*p == ' ') { p++; }
174 182
175 if (*p != ',' && *p != '\0') { 183 if (*p != ',' && *p != '\0') {
176 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE; 184 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
177 break; 185 break;
178 } 186 }
179 187
180 if (end >= r->headers_out.content_length_n || start >= end) { 188 if (suffix) {
189 start = r->headers_out.content_length_n - end;
190 end = r->headers_out.content_length_n - 1;
191 }
192
193 if (start > end) {
181 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE; 194 rc = NGX_HTTP_RANGE_NOT_SATISFIABLE;
182 break; 195 break;
183 } 196 }
184 197
185 ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR); 198 ngx_test_null(range, ngx_push_array(&r->headers_out.ranges), NGX_ERROR);
186 range->start = start; 199 range->start = start;
187 range->end = end + 1; 200
188 201 if (end >= r->headers_out.content_length_n) {
189 if (*p++ == ',') { 202 /*
190 continue; 203 * Download Accelerator sends the last byte position
191 } 204 * that equals to the file length
192 205 */
193 break; 206 range->end = r->headers_out.content_length_n;
207
208 } else {
209 range->end = end + 1;
210 }
211
212 if (*p++ != ',') {
213 break;
214 }
194 } 215 }
195 216
196 if (rc) { 217 if (rc) {
197 218
198 /* rc == NGX_HTTP_RANGE_NOT_SATISFIABLE */ 219 /* rc == NGX_HTTP_RANGE_NOT_SATISFIABLE */