(rpc) extra safeguards in r6867
This commit is contained in:
parent
52a2527963
commit
cceb70b182
|
@ -239,14 +239,17 @@ add_response( struct evhttp_request * req,
|
||||||
stream.next_in = (Bytef*) content;
|
stream.next_in = (Bytef*) content;
|
||||||
stream.avail_in = content_len;
|
stream.avail_in = content_len;
|
||||||
|
|
||||||
|
/* allocate space for the raw data and call deflate() just once --
|
||||||
|
* we won't use the deflated data if it's longer than the raw data,
|
||||||
|
* so it's okay to let deflate() run out of output buffer space */
|
||||||
evbuffer_expand( out, content_len );
|
evbuffer_expand( out, content_len );
|
||||||
stream.next_out = EVBUFFER_DATA( out );
|
stream.next_out = EVBUFFER_DATA( out );
|
||||||
stream.avail_out = content_len;
|
stream.avail_out = content_len;
|
||||||
|
|
||||||
state = deflate( &stream, Z_FINISH );
|
state = deflate( &stream, Z_FINISH );
|
||||||
if( state != Z_STREAM_END )
|
|
||||||
evbuffer_add( out, content, content_len );
|
if( state == Z_STREAM_END )
|
||||||
else {
|
{
|
||||||
EVBUFFER_LENGTH( out ) = content_len - stream.avail_out;
|
EVBUFFER_LENGTH( out ) = content_len - stream.avail_out;
|
||||||
tr_ninf( MY_NAME, _( "Deflated response from %zu bytes to %zu" ),
|
tr_ninf( MY_NAME, _( "Deflated response from %zu bytes to %zu" ),
|
||||||
content_len,
|
content_len,
|
||||||
|
@ -254,6 +257,11 @@ add_response( struct evhttp_request * req,
|
||||||
evhttp_add_header( req->output_headers,
|
evhttp_add_header( req->output_headers,
|
||||||
"Content-Encoding", "deflate" );
|
"Content-Encoding", "deflate" );
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
evbuffer_drain( out, EVBUFFER_LENGTH( out ) );
|
||||||
|
evbuffer_add( out, content, content_len );
|
||||||
|
}
|
||||||
|
|
||||||
deflateEnd( &stream );
|
deflateEnd( &stream );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue