diff -up libsoup-trunk/libsoup/soup-message-io.c libsoup/libsoup/soup-message-io.c --- libsoup-trunk/libsoup/soup-message-io.c 2008-04-03 00:14:55.000000000 +0200 +++ libsoup/libsoup/soup-message-io.c 2008-04-03 00:11:09.000000000 +0200 @@ -59,6 +59,7 @@ typedef struct { SoupMessageBody *write_body; SoupBuffer *write_chunk; gsize write_body_offset; + guint write_length; guint written; guint read_tag, write_tag, err_tag; @@ -507,23 +508,43 @@ io_write (SoupSocket *sock, SoupMessage case SOUP_MESSAGE_IO_STATE_BODY: + + if (io->read_encoding == SOUP_ENCODING_CONTENT_LENGTH) { + SoupMessageHeaders *hdrs = + (io->mode == SOUP_MESSAGE_IO_CLIENT) ? + msg->request_headers : msg->response_headers; + io->write_length = soup_message_headers_get_content_length (hdrs); + } + if (!io->write_chunk) - io->write_chunk = soup_message_body_get_chunk (io->write_body, 0); - if (io->write_chunk) { + io->write_chunk = soup_message_body_get_chunk (io->write_body, io->write_body_offset); + + if (io->write_chunk && io->write_chunk->length != 0) { if (!write_data (msg, io->write_chunk->data, io->write_chunk->length, TRUE)) return; + soup_buffer_free (io->write_chunk); + io->write_body_offset += io->write_chunk->length; io->write_chunk = NULL; - } - - io->write_state = SOUP_MESSAGE_IO_STATE_FINISHING; - - SOUP_MESSAGE_IO_PREPARE_FOR_CALLBACK; - soup_message_wrote_body (msg); - SOUP_MESSAGE_IO_RETURN_IF_CANCELLED_OR_PAUSED; - break; + SOUP_MESSAGE_IO_PREPARE_FOR_CALLBACK; + soup_message_wrote_chunk (msg); + SOUP_MESSAGE_IO_RETURN_IF_CANCELLED_OR_PAUSED; + break; + } + + if (io->written < io->write_length) { + soup_message_io_pause (msg); + break; + } + + io->write_state = SOUP_MESSAGE_IO_STATE_FINISHING; + + SOUP_MESSAGE_IO_PREPARE_FOR_CALLBACK; + soup_message_wrote_body (msg); + SOUP_MESSAGE_IO_RETURN_IF_CANCELLED_OR_PAUSED; + break; case SOUP_MESSAGE_IO_STATE_CHUNK_SIZE: if (!io->write_chunk) {