Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Cherokee: commits

[3771] cherokee/trunk: Fixes Range management while serving static files.

 

 

Cherokee commits RSS feed   Index | Next | Previous | View Threaded


cherokee at cherokee-project

Nov 1, 2009, 10:55 AM

Post #1 of 1 (33 views)
Permalink
[3771] cherokee/trunk: Fixes Range management while serving static files.

Revision: 3771
http://svn.cherokee-project.com/changeset/3771
Author: alo
Date: 2009-11-01 19:55:00 +0100 (Sun, 01 Nov 2009)

Log Message:
-----------
Fixes Range management while serving static files. Patch by Antonio
P?\195?\169rez (great stuff!!!). Fixes: http://bugs.cherokee-project.com/365

Modified Paths:
--------------
cherokee/trunk/cherokee/connection.c
cherokee/trunk/cherokee/handler_error.c
cherokee/trunk/cherokee/handler_file.c
cherokee/trunk/cherokee/handler_file.h
cherokee/trunk/qa/056-ContentRange3.py
cherokee/trunk/qa/057-ContentRange4.py
cherokee/trunk/qa/106-If-Range2.py
cherokee/trunk/qa/145-ContentRange3-NoIO.py
cherokee/trunk/qa/146-ContentRange4-NoIO.py

Modified: cherokee/trunk/cherokee/connection.c
===================================================================
--- cherokee/trunk/cherokee/connection.c 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/cherokee/connection.c 2009-11-01 18:55:00 UTC (rev 3771)
@@ -100,8 +100,8 @@
n->encoder_new_func = NULL;
n->logger_ref = NULL;
n->keepalive = 0;
- n->range_start = 0;
- n->range_end = 0;
+ n->range_start = -1;
+ n->range_end = -1;
n->vserver = NULL;
n->arguments = NULL;
n->realm_ref = NULL;
@@ -254,8 +254,8 @@
conn->upgrade = http_upgrade_nothing;
conn->options = conn_op_log_at_end;
conn->error_code = http_ok;
- conn->range_start = 0;
- conn->range_end = 0;
+ conn->range_start = -1;
+ conn->range_end = -1;
conn->logger_ref = NULL;
conn->realm_ref = NULL;
conn->mmaped = NULL;
@@ -1101,7 +1101,7 @@
/* If this connection has a handler without Content-Length support
* it has to count the bytes sent
*/
- if (!HANDLER_SUPPORTS (conn->handler, hsupport_length)) {
+ if (! HANDLER_SUPPORTS (conn->handler, hsupport_length)) {
conn->range_end += sent;
}

@@ -1654,14 +1654,14 @@
}
tmp[num_len] = '\0';
conn->range_end = strtoll (tmp, (char **)NULL, 10);
- if (conn->range_end < 1){
+ if (conn->range_end < 0){
return ret_error;
}
}

/* Sanity check: switched range
*/
- if ((conn->range_start != 0) && (conn->range_end != 0)) {
+ if ((conn->range_start != -1) && (conn->range_end != -1)) {
if (conn->range_start > conn->range_end) {
conn->error_code = http_range_not_satisfiable;
return ret_error;

Modified: cherokee/trunk/cherokee/handler_error.c
===================================================================
--- cherokee/trunk/cherokee/handler_error.c 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/cherokee/handler_error.c 2009-11-01 18:55:00 UTC (rev 3771)
@@ -264,7 +264,7 @@
* "Content-Range: bytes *" "/" FMT_OFFSET CRLF
*/
cherokee_buffer_add_str (buffer, "Content-Range: bytes */");
- cherokee_buffer_add_ullong10(buffer, (cullong_t)conn->range_end);
+ cherokee_buffer_add_ullong10(buffer, (cullong_t)conn->range_end + 1);
cherokee_buffer_add_str (buffer, CRLF);
}


Modified: cherokee/trunk/cherokee/handler_file.c
===================================================================
--- cherokee/trunk/cherokee/handler_file.c 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/cherokee/handler_file.c 2009-11-01 18:55:00 UTC (rev 3771)
@@ -122,7 +122,6 @@
n->info = NULL;
n->using_sendfile = false;
n->not_modified = false;
- n->range_both = false;

/* Return the object
*/
@@ -268,8 +267,8 @@
if (fhdl->info->st_mtime > req_time) {
conn->error_code = http_ok;

- conn->range_start = 0;
- conn->range_end = 0;
+ conn->range_start = -1;
+ conn->range_end = -1;
}
}

@@ -497,10 +496,10 @@

/* Range 1: Check the range and file size
*/
- if (unlikely ((conn->range_start > fhdl->info->st_size) ||
- (conn->range_end > fhdl->info->st_size)))
+ if (unlikely ((conn->range_start >= fhdl->info->st_size) ||
+ (conn->range_end >= fhdl->info->st_size)))
{
- conn->range_end = fhdl->info->st_size;
+ conn->range_end = fhdl->info->st_size - 1;
conn->error_code = http_range_not_satisfiable;
ret = ret_error;
goto out;
@@ -508,22 +507,24 @@

/* Set the error code
*/
- if ((conn->range_start != 0) &&
- (conn->range_end != 0))
+ if ((conn->range_start > -1) ||
+ (conn->range_end > -1))
{
- fhdl->range_both = true;
conn->error_code = http_partial_content;
-
- } else if ((conn->range_start != 0) ||
- (conn->range_end != 0))
- {
- conn->error_code = http_partial_content;
}

/* Range 2: Set the file length as the range end
*/
- if (conn->range_end == 0) {
- conn->range_end = fhdl->info->st_size;
+ if (conn->range_end == -1) {
+ if (conn->range_start == -1) {
+ conn->range_start = 0;
+ }
+ conn->range_end = fhdl->info->st_size - 1;
+ } else {
+ if (conn->range_start == -1) {
+ conn->range_start = fhdl->info->st_size - conn->range_end;
+ conn->range_end = fhdl->info->st_size - 1;
+ }
}

/* Set mmap or file position
@@ -538,14 +539,10 @@
*/
conn->io_entry_ref = io_entry;

- len = conn->range_end - conn->range_start;
- if ((fhdl->range_both) && (len < io_entry->mmaped_len)) {
- len += 1;
- }
+ len = conn->range_end - conn->range_start + 1;

conn->mmaped = ((char *)io_entry->mmaped) + conn->range_start;
conn->mmaped_len = len;
-
} else {
/* Does no longer care about the io_entry
*/
@@ -692,15 +689,11 @@

/* Content Length
*/
- content_length = conn->range_end - conn->range_start;
+ content_length = conn->range_end - conn->range_start + 1;
if (unlikely (content_length < 0)) {
content_length = 0;
}

- if (fhdl->range_both) {
- content_length += 1;
- }
-
if (conn->error_code == http_partial_content) {
/*
* "Content-Range: bytes " FMT_OFFSET "-" FMT_OFFSET
@@ -731,25 +724,16 @@
cherokee_handler_file_step (cherokee_handler_file_t *fhdl, cherokee_buffer_t *buffer)
{
off_t total;
- off_t end;
size_t size;
cherokee_connection_t *conn = HANDLER_CONN(fhdl);

- /* End point
- */
- if (fhdl->range_both) {
- end = conn->range_end + 1;
- } else {
- end = conn->range_end;
- }
-
#ifdef WITH_SENDFILE
if (fhdl->using_sendfile) {
ret_t ret;
ssize_t sent;
off_t to_send;

- to_send = end - fhdl->offset;
+ to_send = conn->range_end - fhdl->offset + 1;
if ((conn->limit_bps > 0) &&
(conn->limit_bps < to_send))
{
@@ -785,7 +769,7 @@
*/
cherokee_connection_tx_add (conn, sent);

- if (fhdl->offset >= end) {
+ if (fhdl->offset >= conn->range_end) {
return ret_eof;
}

@@ -797,8 +781,8 @@
/* Check the amount to read
*/
size = buffer->size - 1;
- if (size > (end - fhdl->offset)) {
- size = end - fhdl->offset;
+ if (size > (conn->range_end - fhdl->offset + 1)) {
+ size = conn->range_end - fhdl->offset + 1;
} else {
/* Align read size on a 4 byte limit
*/
@@ -812,7 +796,7 @@

/* Read
*/
- total = read (fhdl->fd, buffer->buf, size);
+ total = read (fhdl->fd, buffer->buf, size);
switch (total) {
case 0:
return ret_eof;
@@ -826,7 +810,7 @@

/* Maybe it was the last file chunk
*/
- if (fhdl->offset >= end) {
+ if (fhdl->offset >= conn->range_end) {
return ret_eof_have_data;
}


Modified: cherokee/trunk/cherokee/handler_file.h
===================================================================
--- cherokee/trunk/cherokee/handler_file.h 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/cherokee/handler_file.h 2009-11-01 18:55:00 UTC (rev 3771)
@@ -55,7 +55,6 @@
cherokee_mime_entry_t *mime;
struct stat cache_info;

- cherokee_boolean_t range_both;
cherokee_boolean_t using_sendfile;
cherokee_boolean_t not_modified;
} cherokee_handler_file_t;

Modified: cherokee/trunk/qa/056-ContentRange3.py
===================================================================
--- cherokee/trunk/qa/056-ContentRange3.py 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/qa/056-ContentRange3.py 2009-11-01 18:55:00 UTC (rev 3771)
@@ -16,7 +16,9 @@
self.request = "GET /Range100b2 HTTP/1.0\r\n" +\
"Range: bytes=-%d\r\n" % (OFFSET)
self.expected_error = 206
- self.expected_content = [MAGIC[:OFFSET], "Content-Length: %d" % (OFFSET)]
+ self.expected_content = [MAGIC[-OFFSET:],
+ "Content-Length: %d" % (OFFSET),
+ "Content-Range: bytes %d-%d/%d" % (LENGTH-OFFSET, LENGTH-1, LENGTH)]
self.forbidden_content = MAGIC[OFFSET:]

def Prepare (self, www):

Modified: cherokee/trunk/qa/057-ContentRange4.py
===================================================================
--- cherokee/trunk/qa/057-ContentRange4.py 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/qa/057-ContentRange4.py 2009-11-01 18:55:00 UTC (rev 3771)
@@ -22,8 +22,9 @@

forbidden = self.WriteTemp (srandom[OFFSET:])

- self.expected_content = [srandom[:OFFSET],
- "Content-Length: %d" % (OFFSET)]
+ self.expected_content = [srandom[-OFFSET:],
+ "Content-Length: %d" % (OFFSET),
+ "Content-Range: bytes %d-%d/%d" % (LENGTH-OFFSET, LENGTH-1, LENGTH)]
self.forbidden_content = "file:" + forbidden



Modified: cherokee/trunk/qa/106-If-Range2.py
===================================================================
--- cherokee/trunk/qa/106-If-Range2.py 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/qa/106-If-Range2.py 2009-11-01 18:55:00 UTC (rev 3771)
@@ -25,9 +25,13 @@
self.name = "If-Range header, 206 error"

self.conf = CONF
+ self.forbidden_content = DOCUMENTATION
self.expected_error = 206
- self.forbidden_content = DOCUMENTATION

+ l = len(DOCUMENTATION)
+ self.expected_content = ["Content-Length: 1",
+ "Content-Range: bytes %d-%d/%d" %(l-1, l-1, l)]
+
def Prepare (self, www):
d = self.Mkdir (www, "if_range2")
f = self.WriteFile (d, "file", 0444, DOCUMENTATION)
@@ -40,4 +44,4 @@
"Host: localhost\r\n" + \
"Connection: Close\r\n" + \
"If-Range: %s\r\n" % (times) + \
- "Range: bytes=%d-\r\n" % (len(DOCUMENTATION))
+ "Range: bytes=%d-\r\n" % (len(DOCUMENTATION)-1)

Modified: cherokee/trunk/qa/145-ContentRange3-NoIO.py
===================================================================
--- cherokee/trunk/qa/145-ContentRange3-NoIO.py 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/qa/145-ContentRange3-NoIO.py 2009-11-01 18:55:00 UTC (rev 3771)
@@ -22,9 +22,12 @@

self.request = "GET /%s/Range100b2 HTTP/1.0\r\n" % (DIR) +\
"Range: bytes=-%d\r\n" % (OFFSET)
+
+ self.forbidden_content = MAGIC[OFFSET:]
self.expected_error = 206
- self.expected_content = [MAGIC[:OFFSET], "Content-Length: %d" % (OFFSET)]
- self.forbidden_content = MAGIC[OFFSET:]
+ self.expected_content = [MAGIC[-OFFSET:],
+ "Content-Length: %d" % (OFFSET),
+ "Content-Range: bytes %d-%d/%d" % (LENGTH-OFFSET, LENGTH-1, LENGTH)]

def Prepare (self, www):
test_dir = self.Mkdir (www, DIR)

Modified: cherokee/trunk/qa/146-ContentRange4-NoIO.py
===================================================================
--- cherokee/trunk/qa/146-ContentRange4-NoIO.py 2009-10-31 23:01:59 UTC (rev 3770)
+++ cherokee/trunk/qa/146-ContentRange4-NoIO.py 2009-11-01 18:55:00 UTC (rev 3771)
@@ -32,5 +32,7 @@

forbidden = self.WriteTemp (srandom[OFFSET:])

- self.expected_content = [srandom[:OFFSET], "Content-Length: %d" % (OFFSET)]
self.forbidden_content = "file:" + forbidden
+ self.expected_content = [srandom[-OFFSET:],
+ "Content-Length: %d" % (OFFSET),
+ "Content-Range: bytes %d-%d/%d" % (LENGTH-OFFSET, LENGTH-1, LENGTH)]

Cherokee commits RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.