[rygel] core: Fix Content-Length: for partial requests



commit 3e783e78be2c2d6a7af4fc4d2b76731940f3ec89
Author: Jens Georg <mail jensge org>
Date:   Sat Oct 24 02:45:50 2009 +0200

    core: Fix Content-Length: for partial requests

 src/rygel/rygel-http-identity-handler.vala |    2 ++
 src/rygel/rygel-seekable-response.vala     |   10 ++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/src/rygel/rygel-http-identity-handler.vala b/src/rygel/rygel-http-identity-handler.vala
index 785a66a..94aaf37 100644
--- a/src/rygel/rygel-http-identity-handler.vala
+++ b/src/rygel/rygel-http-identity-handler.vala
@@ -56,6 +56,8 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPRequestHandler {
         } else {
             request.msg.response_headers.append ("Accept-Ranges", "bytes");
             if (request.byte_range != null) {
+                request.msg.response_headers.set_content_length (
+                                                   request.byte_range.length);
                 request.byte_range.add_response_header (request.msg, size);
             }
         }
diff --git a/src/rygel/rygel-seekable-response.vala b/src/rygel/rygel-seekable-response.vala
index c1088ab..5d7cb2c 100644
--- a/src/rygel/rygel-seekable-response.vala
+++ b/src/rygel/rygel-seekable-response.vala
@@ -110,10 +110,15 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
         yield this.close_stream ();
     }
 
+    private size_t bytes_to_read () {
+        return size_t.min (this.total_length,
+                           SeekableResponse.BUFFER_LENGTH);
+    }
+
     private async void read_contents () throws Error {
         var bytes_read = yield this.input_stream.read_async (
                                         this.buffer,
-                                        SeekableResponse.BUFFER_LENGTH,
+                                        this.bytes_to_read (),
                                         this.priority,
                                         this.cancellable);
         SourceFunc cb = read_contents.callback;
@@ -123,6 +128,7 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
 
         while (bytes_read > 0) {
             this.push_data (this.buffer, bytes_read);
+            this.total_length -= bytes_read;
 
             // We return from this call when wrote_chunk signal is emitted
             // and the handler we installed before the loop is called for it.
@@ -130,7 +136,7 @@ internal class Rygel.SeekableResponse : Rygel.HTTPResponse {
 
             bytes_read = yield this.input_stream.read_async (
                                         this.buffer,
-                                        SeekableResponse.BUFFER_LENGTH,
+                                        this.bytes_to_read (),
                                         this.priority,
                                         this.cancellable);
         }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]