Ensure read_callback is non-NULL for response bodies.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-02-21 22:04:24 +09:00
parent f404142b17
commit 37944253d2
4 changed files with 26 additions and 2 deletions

View File

@ -53,7 +53,7 @@ int spdylay_submit_response(spdylay_session *session,
char **nv_copy;
uint8_t flags = 0;
spdylay_data_provider *data_prd_copy = NULL;
if(data_prd) {
if(data_prd != NULL && data_prd->read_callback != NULL) {
data_prd_copy = malloc(sizeof(spdylay_data_provider));
if(data_prd_copy == NULL) {
return SPDYLAY_ERR_NOMEM;
@ -73,7 +73,7 @@ int spdylay_submit_response(spdylay_session *session,
}
spdylay_frame_nv_downcase(nv_copy);
spdylay_frame_nv_sort(nv_copy);
if(data_prd == NULL) {
if(data_prd_copy == NULL) {
flags |= SPDYLAY_FLAG_FIN;
}
spdylay_frame_syn_reply_init(&frame->syn_reply, flags, stream_id,

View File

@ -85,6 +85,8 @@ int main(int argc, char* argv[])
!CU_add_test(pSuite, "session_send_syn_reply",
test_spdylay_session_send_syn_reply) ||
!CU_add_test(pSuite, "submit_response", test_spdylay_submit_response) ||
!CU_add_test(pSuite, "submit_response_without_data",
test_spdylay_submit_response_with_null_data_read_callback) ||
!CU_add_test(pSuite, "submit_request_with_data",
test_spdylay_submit_request_with_data) ||
!CU_add_test(pSuite, "submit_request_without_data",

View File

@ -564,6 +564,27 @@ void test_spdylay_submit_response()
spdylay_session_del(session);
}
void test_spdylay_submit_response_with_null_data_read_callback()
{
spdylay_session *session;
spdylay_session_callbacks callbacks;
const char *nv[] = { "Version", "HTTP/1.1", NULL };
spdylay_data_provider data_prd = {{-1}, NULL};
spdylay_outbound_item *item;
memset(&callbacks, 0, sizeof(callbacks));
callbacks.send_callback = null_send_callback;
CU_ASSERT(0 == spdylay_session_server_new(&session, &callbacks, NULL));
spdylay_session_open_stream(session, 1, SPDYLAY_FLAG_FIN, 3,
SPDYLAY_STREAM_OPENING, NULL);
CU_ASSERT(0 == spdylay_submit_response(session, 1, nv, &data_prd));
item = spdylay_session_get_next_ob_item(session);
CU_ASSERT(0 == strcmp("version", item->frame->syn_reply.nv[0]));
CU_ASSERT(item->frame->syn_reply.hd.flags & SPDYLAY_FLAG_FIN);
spdylay_session_del(session);
}
void test_spdylay_submit_request_with_data()
{
spdylay_session *session;

View File

@ -34,6 +34,7 @@ void test_spdylay_session_on_syn_reply_received();
void test_spdylay_session_send_syn_stream();
void test_spdylay_session_send_syn_reply();
void test_spdylay_submit_response();
void test_spdylay_submit_response_with_null_data_read_callback();
void test_spdylay_submit_request_with_data();
void test_spdylay_submit_request_with_null_data_read_callback();
void test_spdylay_session_reply_fail();