Project

General

Profile

x-sendfile-range.patch

r2522 patch to add X-Sendfile-Range header support to 1.4.x. - shellsage, 2009-06-11 06:07

View differences:

src/mod_fastcgi.c (working copy)
2559 2559
							dcls = data_response_init();
2560 2560
						}
2561 2561
						/* found */
2562
						http_chunk_append_file(srv, con, ds->value, 0, sce->st.st_size);
2562
						/* Assume we should serve from the beginning to the end of the file. */
2563
						/* If they gave us X-Sendfile-Range, adjust portion to serve. */
2564
						long start = 0;
2565
						long end = sce->st.st_size;
2566
						data_string *dsr;
2567
						if (NULL != (dsr = (data_string *) array_get_element(con->response.headers, "X-Sendfile-Range"))) {
2568
							char *range_part = strtok(dsr->value->ptr, " ");
2569
							int on_start = 1;
2570
							while(range_part != NULL) {
2571
								if(on_start == 1) {
2572
									start = atol(range_part);
2573
								} else {
2574
									end = atol(range_part);
2575
									break;
2576
								}
2577
								on_start = 0;
2578
								range_part = strtok(NULL, " ");
2579
							}
2580
							if(end > sce->st.st_size) {
2581
								end = sce->st.st_size;
2582
							}
2583
						}
2584
						long length = end - start;
2585
						http_chunk_append_file(srv, con, ds->value, start, end);
2563 2586
						hctx->send_content_body = 0; /* ignore the content */
2564 2587
						joblist_append(srv, con);
2565 2588

  
2566 2589
						buffer_copy_string_len(dcls->key, "Content-Length", sizeof("Content-Length")-1);
2567
						buffer_copy_off_t(dcls->value, sce->st.st_size);
2590
						buffer_copy_off_t(dcls->value, length);
2568 2591
						dcls = (data_string*) array_replace(con->response.headers, (data_unset *)dcls);
2569 2592
						if (dcls) dcls->free((data_unset*)dcls);
2570 2593

  
2571 2594
						con->parsed_response |= HTTP_CONTENT_LENGTH;
2572
						con->response.content_length = sce->st.st_size;
2595
						con->response.content_length = length;
2573 2596
					} else {
2574 2597
						log_error_write(srv, __FILE__, __LINE__, "sb",
2575 2598
							"send-file error: couldn't get stat_cache entry for:",
src/response.c (working copy)
65 65

  
66 66
		if (ds->value->used && ds->key->used &&
67 67
		    0 != strncasecmp(ds->key->ptr, CONST_STR_LEN("X-LIGHTTPD-")) &&
68
			0 != strcasecmp(ds->key->ptr, "X-Sendfile")) {
68
			0 != strcasecmp(ds->key->ptr, "X-Sendfile") &&
69
			0 != strcasecmp(ds->key->ptr, "X-Sendfile-Range")) {
69 70
			if (0 == strcasecmp(ds->key->ptr, "Date")) have_date = 1;
70 71
			if (0 == strcasecmp(ds->key->ptr, "Server")) have_server = 1;
71 72
			if (0 == strcasecmp(ds->key->ptr, "Content-Encoding") && 304 == con->http_status) continue;