From: hamza zia <[email protected]>

Some plugins may want to support HTTP range requests so it is parsed and
filled in the request headers before calling the plugin.
---
 src/mk_http.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/mk_http.c b/src/mk_http.c
index 0f8a976..700cbda 100644
--- a/src/mk_http.c
+++ b/src/mk_http.c
@@ -135,6 +135,9 @@ static int mk_http_range_set(struct session_request *sr, 
long file_size)
 
         lseek(sr->fd_file, sr->bytes_offset, SEEK_SET);
     }
+
+    sh->content_length = sr->bytes_to_send;
+
     return 0;
 }
 
@@ -168,7 +171,6 @@ static int mk_http_range_parse(struct session_request *sr)
             return -1;
         }
 
-        sh->content_length = sh->ranges[1];
         return 0;
     }
 
@@ -186,16 +188,15 @@ static int mk_http_range_parse(struct session_request *sr)
             return -1;
         }
 
-        sh->content_length = abs(sh->ranges[1] - sh->ranges[0]) + 1;
         return 0;
     }
     /* =yyy- */
     if ((eq_pos + 1 != sep_pos) && (len == sep_pos + 1)) {
         buffer = mk_string_copy_substr(sr->range.data, eq_pos + 1, len);
         sr->headers.ranges[0] = (unsigned long) atol(buffer);
+        sr->headers.ranges[1] = -1;
         mk_mem_free(buffer);
 
-        sh->content_length = (sh->content_length - sh->ranges[0]);
         return 0;
     }
 
@@ -372,6 +373,11 @@ int mk_http_init(struct client_session *cs, struct 
session_request *sr)
         return mk_request_error(MK_CLIENT_FORBIDDEN, cs, sr);
     }
 
+    /* Parse HTTP Ranges */
+    sr->headers.ranges[0] = sr->headers.ranges[1] = -1;
+    if (sr->range.data != NULL && mk_http_range_parse(sr) < 0) {
+        return mk_request_error(MK_CLIENT_BAD_REQUEST, cs, sr);
+    }
 
     if (mk_file_get_info(sr->real_path.data, &sr->file_info) != 0) {
         /* if the resource requested doesn't exists, let's
@@ -546,13 +552,8 @@ int mk_http_init(struct client_session *cs, struct 
session_request *sr)
     if (sr->method == HTTP_METHOD_GET || sr->method == HTTP_METHOD_HEAD) {
         sr->headers.content_type = mime->type;
 
-        /* HTTP Ranges */
-        if (sr->range.data != NULL && config->resume == MK_TRUE) {
-            if (mk_http_range_parse(sr) < 0) {
-                sr->headers.ranges[0] = -1;
-                sr->headers.ranges[1] = -1;
-                return mk_request_error(MK_CLIENT_BAD_REQUEST, cs, sr);
-            }
+        /* Use parsed HTTP Range if available */
+        if (config->resume == MK_TRUE) {
             if (sr->headers.ranges[0] >= 0 || sr->headers.ranges[1] >= 0) {
                 mk_header_set_http_status(sr, MK_HTTP_PARTIAL);
             }
-- 
1.8.1.2

_______________________________________________
Monkey mailing list
[email protected]
http://lists.monkey-project.com/listinfo/monkey

Reply via email to