fix connection handling with chunked responses

personal/stbuehler/wip
Stefan Bühler 10 years ago
parent ff28617976
commit 914f79650a

@ -184,6 +184,7 @@ static void connection_check_reset(liJob *job) {
}
}
/* tcp/ssl -> http "parser" */
static void _connection_http_in_cb(liStream *stream, liStreamEvent event) {
liConnection *con = LI_CONTAINER_OF(stream, liConnection, in);
liChunkQueue *raw_in, *in;
@ -351,6 +352,7 @@ static void _connection_http_in_cb(liStream *stream, liStreamEvent event) {
}
}
/* http response header/data -> tcp/ssl */
static void _connection_http_out_cb(liStream *stream, liStreamEvent event) {
liConnection *con = LI_CONTAINER_OF(stream, liConnection, out);
@ -367,7 +369,7 @@ static void _connection_http_out_cb(liStream *stream, liStreamEvent event) {
if (!con->out_has_all_data) li_connection_error(con);
return;
case LI_STREAM_DISCONNECTED_DEST:
if (!raw_out->is_closed || NULL == con->con_sock.raw_out) {
if (!raw_out->is_closed || 0 != raw_out->length || NULL == con->con_sock.raw_out) {
li_connection_error(con);
} else {
connection_close(con);
@ -398,9 +400,10 @@ static void _connection_http_out_cb(liStream *stream, liStreamEvent event) {
li_response_send_headers(vr, raw_out, out);
}
if (!raw_out->is_closed && NULL != out) {
if (!con->out_has_all_data && !raw_out->is_closed && NULL != out) {
if (vr->response.transfer_encoding & LI_HTTP_TRANSFER_ENCODING_CHUNKED) {
li_filter_chunked_encode(vr, raw_out, out);
raw_out->is_closed = FALSE;
} else {
li_chunkqueue_steal_all(raw_out, out);
}
@ -723,11 +726,13 @@ static void li_connection_reset_keep_alive(liConnection *con) {
con->info.keep_alive = TRUE;
con->out.out->is_closed = FALSE;
li_vrequest_reset(con->mainvr, TRUE);
li_http_request_parser_reset(&con->req_parser_ctx);
li_stream_disconnect(&con->out);
li_stream_disconnect_dest(&con->in);
con->out.out->is_closed = FALSE;
/* restore chunkqueue limits */
li_chunkqueue_use_limit(con->con_sock.raw_in->out, 512*1024);
li_chunkqueue_use_limit(con->con_sock.raw_out->out, 512*1024);

@ -28,6 +28,7 @@ static void stream_http_respone_data(liStreamHttpResponse* shr) {
VR_ERROR(shr->vr, "%s", "Parsing response header failed (eos)");
li_vrequest_error(shr->vr);
}
return;
default:
return;
}
@ -42,7 +43,7 @@ static void stream_http_respone_data(liStreamHttpResponse* shr) {
}
static void stream_http_respone_cb(liStream *stream, liStreamEvent event) {
static void stream_http_response_cb(liStream *stream, liStreamEvent event) {
liStreamHttpResponse* shr = LI_CONTAINER_OF(stream, liStreamHttpResponse, stream);
switch (event) {
@ -71,7 +72,7 @@ LI_API liStream* li_stream_http_response_handle(liStream *http_in, liVRequest *v
liStreamHttpResponse *shr = g_slice_new0(liStreamHttpResponse);
shr->response_headers_finished = FALSE;
shr->vr = vr;
li_stream_init(&shr->stream, &vr->wrk->loop, stream_http_respone_cb);
li_stream_init(&shr->stream, &vr->wrk->loop, stream_http_response_cb);
li_http_response_parser_init(&shr->parse_response_ctx, &vr->response, http_in->out,
accept_cgi, accept_nph);
li_stream_connect(http_in, &shr->stream);

Loading…
Cancel
Save