static void setup_request_body (PutTestData *ptd) { make_put_chunk (&ptd->chunks[0], "one\r\n"); make_put_chunk (&ptd->chunks[1], "two\r\n"); make_put_chunk (&ptd->chunks[2], "three\r\n"); ptd->next = ptd->nwrote = ptd->nfreed = 0; }
static void restarted_streaming_hack (SoupMessage *msg, gpointer user_data) { PutTestData *ptd = user_data; /* We're streaming, and we had to restart. So the data need to be regenerated. That's the *point* of this test; we don't *want* it to accumulate in the request body */ make_put_chunk (&ptd->chunks[0], "one\r\n"); make_put_chunk (&ptd->chunks[1], "two\r\n"); make_put_chunk (&ptd->chunks[2], "three\r\n"); ptd->next = ptd->nwrote = ptd->nfreed = 0; debug_printf (2, " truncating request body on restart\n"); soup_message_body_truncate (msg->request_body); /* The redirect will turn it into a GET request. Fix that... */ soup_message_headers_set_encoding (msg->request_headers, SOUP_ENCODING_CHUNKED); msg->method = SOUP_METHOD_PUT; }
static void do_request_test (SoupSession *session, SoupURI *base_uri, int test) { SoupURI *uri = base_uri; PutTestData ptd; SoupMessage *msg; const char *client_md5, *server_md5; GChecksum *check; int i, length; gboolean streaming = FALSE; switch (test) { case 0: debug_printf (1, "PUT\n"); break; case 1: debug_printf (1, "PUT w/ streaming\n"); streaming = TRUE; break; case 2: debug_printf (1, "PUT w/ streaming and restart\n"); streaming = TRUE; uri = soup_uri_copy (base_uri); soup_uri_set_path (uri, "/redirect"); break; } ptd.session = session; make_put_chunk (&ptd.chunks[0], "one\r\n"); make_put_chunk (&ptd.chunks[1], "two\r\n"); make_put_chunk (&ptd.chunks[2], "three\r\n"); ptd.next = ptd.nwrote = ptd.nfreed = 0; ptd.streaming = streaming; check = g_checksum_new (G_CHECKSUM_MD5); length = 0; for (i = 0; i < 3; i++) { g_checksum_update (check, (guchar *)ptd.chunks[i]->data, ptd.chunks[i]->length); length += ptd.chunks[i]->length; } client_md5 = g_checksum_get_string (check); msg = soup_message_new_from_uri ("PUT", uri); soup_message_headers_set_encoding (msg->request_headers, SOUP_ENCODING_CHUNKED); soup_message_body_set_accumulate (msg->request_body, FALSE); soup_message_set_chunk_allocator (msg, error_chunk_allocator, NULL, NULL); if (streaming) { g_signal_connect (msg, "wrote_chunk", G_CALLBACK (write_next_chunk_streaming_hack), &ptd); g_signal_connect (msg, "restarted", G_CALLBACK (restarted_streaming_hack), &ptd); } else { g_signal_connect (msg, "wrote_chunk", G_CALLBACK (write_next_chunk), &ptd); } g_signal_connect (msg, "wrote_headers", G_CALLBACK (write_next_chunk), &ptd); g_signal_connect (msg, "wrote_body_data", G_CALLBACK (wrote_body_data), &ptd); soup_session_send_message (session, msg); if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { debug_printf (1, " message failed: %d %s\n", msg->status_code, msg->reason_phrase); errors++; } if (msg->request_body->data) { debug_printf (1, " msg->request_body set!\n"); errors++; } if (msg->request_body->length != length || length != ptd.nwrote) { debug_printf (1, " sent length mismatch: %d vs %d vs %d\n", (int)msg->request_body->length, length, ptd.nwrote); errors++; } server_md5 = soup_message_headers_get_one (msg->response_headers, "Content-MD5"); if (!server_md5 || strcmp (client_md5, server_md5) != 0) { debug_printf (1, " client/server data mismatch: %s vs %s\n", client_md5, server_md5 ? server_md5 : "(null)"); errors++; } g_object_unref (msg); g_checksum_free (check); if (uri != base_uri) soup_uri_free (uri); }