aboutsummaryrefslogtreecommitdiffstats
path: root/lib/http_client.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2012-11-11 17:57:20 +0000
committerWilmer van der Gaast <wilmer@gaast.net>2012-11-11 17:57:20 +0000
commit1388d303ba0d2097ff745d4a17192195cebbd349 (patch)
tree80abf227c150858e4949b4658229f19c3379b767 /lib/http_client.c
parent62f6b45d2056b90f57b908cd9bc9b6a995365c43 (diff)
Mostly finished HTTP streaming support: Shrink the buffer and add a
http_close().
Diffstat (limited to 'lib/http_client.c')
-rw-r--r--lib/http_client.c28
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/http_client.c b/lib/http_client.c
index acbf230c..5fc7731f 100644
--- a/lib/http_client.c
+++ b/lib/http_client.c
@@ -567,13 +567,35 @@ static gboolean http_handle_headers( struct http_request *req )
void http_flush_bytes( struct http_request *req, size_t len )
{
- if( len > 0 && len <= req->body_size )
+ if( len <= 0 || len > req->body_size || !( req->flags & HTTPC_STREAMING ) )
+ return;
+
+ req->reply_body += len;
+ req->body_size -= len;
+
+ if( req->reply_body - req->sbuf >= 512 )
{
- req->reply_body += len;
- req->body_size -= len;
+ printf( "Wasting %ld bytes, cleaning up stream buffer\n", req->reply_body - req->sbuf );
+ char *new = g_memdup( req->reply_body, req->body_size + 1 );
+ g_free( req->sbuf );
+ req->reply_body = req->sbuf = new;
+ req->sblen = req->body_size;
}
}
+void http_close( struct http_request *req )
+{
+ if( !req )
+ return;
+
+ if( req->ssl )
+ ssl_disconnect( req->ssl );
+ else
+ closesocket( req->fd );
+
+ http_free( req );
+}
+
static void http_free( struct http_request *req )
{
g_free( req->request );