diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-01-06 20:21:31 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-01-06 20:21:31 +0000 |
commit | 3d0152c7bbf00115eb4aeddd98f16a17705e2308 (patch) | |
tree | 4c3a80958dcbb9e6e55658deca60cfcf9f95a6d9 /src/daemon | |
parent | 28cba57e89f9c2886bfc1699dfcd431317cfb285 (diff) | |
download | libmicrohttpd-3d0152c7bbf00115eb4aeddd98f16a17705e2308.tar.gz libmicrohttpd-3d0152c7bbf00115eb4aeddd98f16a17705e2308.zip |
allow 0-byte responses with response_from_callback
Diffstat (limited to 'src/daemon')
-rw-r--r-- | src/daemon/connection.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/daemon/connection.c b/src/daemon/connection.c index b612b8e7..727300a6 100644 --- a/src/daemon/connection.c +++ b/src/daemon/connection.c | |||
@@ -370,6 +370,8 @@ try_ready_normal_body (struct MHD_Connection *connection) | |||
370 | response = connection->response; | 370 | response = connection->response; |
371 | if (NULL == response->crc) | 371 | if (NULL == response->crc) |
372 | return MHD_YES; | 372 | return MHD_YES; |
373 | if (0 == response->data_size) | ||
374 | return MHD_YES; /* 0-byte response is always ready */ | ||
373 | if ( (response->data_start <= | 375 | if ( (response->data_start <= |
374 | connection->response_write_position) && | 376 | connection->response_write_position) && |
375 | (response->data_size + response->data_start > | 377 | (response->data_size + response->data_start > |
@@ -477,10 +479,13 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
477 | else | 479 | else |
478 | { | 480 | { |
479 | /* buffer not in range, try to fill it */ | 481 | /* buffer not in range, try to fill it */ |
480 | ret = response->crc (response->crc_cls, | 482 | if (0 == response->data_size) |
481 | connection->response_write_position, | 483 | ret = 0; /* response must be empty, don't bother calling crc */ |
482 | &connection->write_buffer[sizeof (cbuf)], | 484 | else |
483 | connection->write_buffer_size - sizeof (cbuf) - 2); | 485 | ret = response->crc (response->crc_cls, |
486 | connection->response_write_position, | ||
487 | &connection->write_buffer[sizeof (cbuf)], | ||
488 | connection->write_buffer_size - sizeof (cbuf) - 2); | ||
484 | } | 489 | } |
485 | if (MHD_CONTENT_READER_END_WITH_ERROR == ret) | 490 | if (MHD_CONTENT_READER_END_WITH_ERROR == ret) |
486 | { | 491 | { |
@@ -490,7 +495,8 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
490 | "Closing connection (error generating response)\n"); | 495 | "Closing connection (error generating response)\n"); |
491 | return MHD_NO; | 496 | return MHD_NO; |
492 | } | 497 | } |
493 | if (MHD_CONTENT_READER_END_OF_STREAM == ret) | 498 | if ( (MHD_CONTENT_READER_END_OF_STREAM == ret) || |
499 | (0 == response->data_size) ) | ||
494 | { | 500 | { |
495 | /* end of message, signal other side! */ | 501 | /* end of message, signal other side! */ |
496 | strcpy (connection->write_buffer, "0\r\n"); | 502 | strcpy (connection->write_buffer, "0\r\n"); |
@@ -499,7 +505,7 @@ try_ready_chunked_body (struct MHD_Connection *connection) | |||
499 | response->total_size = connection->response_write_position; | 505 | response->total_size = connection->response_write_position; |
500 | return MHD_YES; | 506 | return MHD_YES; |
501 | } | 507 | } |
502 | if (0 == ret) | 508 | if (0 == ret) |
503 | { | 509 | { |
504 | connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; | 510 | connection->state = MHD_CONNECTION_CHUNKED_BODY_UNREADY; |
505 | return MHD_NO; | 511 | return MHD_NO; |