Re: Pushing a large file to HTTP 1.0 clients without chunked transfer encoding
- From: Dan Winship <danw gnome org>
- To: "W. Michael Petullo" <mike flyn org>
- Cc: libsoup-list gnome org
- Subject: Re: Pushing a large file to HTTP 1.0 clients without chunked transfer encoding
- Date: Tue, 17 Feb 2009 09:44:38 -0500
W. Michael Petullo wrote:
> The solution I'd like to use is to set "Connection: Close" in the HTTP
> header and then just skip the "Content-Length" header. Then, I should be
> able to write to the connection byte by byte. This seems compliant with
> HTTP 1.0 as RFC 1945 seems to state that the Content-Length is optional
> for HTTP responses.
>
> Does the libsoup API allow me to do something like this?
Hm... you ought to be able to do this, but looking at the code, it seems
like the HTTP I/O code doesn't actually deal correctly with the
"response body ends with connection close" case. (Now filed as
http://bugzilla.gnome.org/show_bug.cgi?id=572153.)
Do you know in advance how large the response is going to be? If so, you
can use Content-Length, but provide the response a little bit at a time
instead of all at once. Do this from your SoupServer handler:
soup_message_headers_set_content_length (msg->response_headers,
total_length);
soup_message_body_set_accumulate (msg->response_body, FALSE);
(The first call tells it what to put into the Content-Length header, and
the second tells it that it should throw away the body data after it
writes it, rather than accumulating it all at the end.)
Then use soup_message_body_append() to add each piece of the response.
Writing out the response a bit at a time is slightly tricky, but the
easiest way is to make the first call to soup_message_body_append() from
the server handler, and then connect to the "wrote-chunk" signal on the
message, and then each time the signal handler is called, add another
chunk, until you're done. (When you're done, just don't add any more
chunks; you already told libsoup the total length, so it knows when to
stop writing.)
You probably don't really want to write the response "byte by byte", but
just generate it in whatever size pieces are convenient for you.
plugins/daap/rb-daap-share.c in rhythmbox is one example of doing
something like this. (They're actually using chunked encoding, so the
setup is a little different, and they have to call
soup_message_body_complete() at the end, but on the whole, it's pretty
similar.)
-- Dan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]