Project

General

Profile

x-sendfile-extended.patch

r2539 patch to add X-Sendfile-Extended support - shellsage, 2009-06-15 02:54

View differences:

src/mod_fastcgi.c (working copy)
2305 2305
				if (con->response.content_length < 0) con->response.content_length = 0;
2306 2306
			}
2307 2307
			break;
2308
		case 19:
2309
			if (0 == strncasecmp(key, "X-Sendfile-Extended", key_len) && host->allow_xsendfile) {
2310
				/* Header of the form: X-Sendfile-Extended: [begin-byte] [end-byte] [file] */
2311
				/* Parse the header into different components */
2312
				off_t start = 0, end = 0, len;
2313
				char *end_part = NULL, *final_part = NULL;
2314
				start = strtoll(value, &end_part, 10);
2315
				if (end_part && *end_part) {
2316
					end = strtoll(end_part, &final_part, 10);
2317
				}
2318
				
2319
				stat_cache_entry *sce;
2320
				buffer *dsp;
2321
				dsp = buffer_init_buffer(dsp);
2322
				/* final_part+1 to get rid of the mandatory space after [end-byte] */
2323
				/* Also works as: X-Sendfile-Extended: [begin-byte] [end-byte][file] */
2324
				buffer_copy_string(dsp, final_part+1);
2325
				if (HANDLER_ERROR != stat_cache_get_entry(srv, con, dsp, &sce)) {
2326
					if (start < 0 || end_part == value) {
2327
						start = 0;
2328
						log_error_write(srv, __FILE__, __LINE__, "ss",
2329
								"Invalid X-Sendfile-Extended header:",
2330
								value);
2331
					}
2332
					if (end_part == final_part) {
2333
						end = 0;
2334
						log_error_write(srv, __FILE__, __LINE__, "ss",
2335
								"Invalid X-Sendfile-Extended header:",
2336
								value);
2337
					} else if (end < 0 || end > sce->st.st_size) {
2338
						end = sce->st.st_size;
2339
					}
2340
					if (start > end) {
2341
						start = end;
2342
					}
2343
				} else {
2344
					log_error_write(srv, __FILE__, __LINE__, "sb",
2345
						"X-Sendfile-Extended error: couldn't get stat_cache entry for:",
2346
						dsp);
2347
				}
2348
				len = end - start;
2349
				if (len != 0) http_chunk_append_file(srv, con, dsp, start, len);
2350
				hctx->send_content_body = 0; /* ignore the content */
2351
				joblist_append(srv, con);
2352
				con->response.content_length += len;
2353
			}
2354
			break;
2308 2355
		default:
2309 2356
			break;
2310 2357
		}