static void restarted_streaming (SoupMessage *msg, gpointer user_data) { PutTestData *ptd = user_data; debug_printf (2, " --restarting--\n"); /* We're streaming, and we had to restart. So the data need * to be regenerated. */ setup_request_body (ptd); /* The 302 redirect will turn it into a GET request and * reset the body encoding back to "NONE". Fix that. */ soup_message_headers_set_encoding (msg->request_headers, SOUP_ENCODING_CHUNKED); msg->method = SOUP_METHOD_PUT; }
void https_request(struct https_engine *https, const char *host, int port, const char *method, const char *path, const char *access_token, struct evbuffer *body, struct https_cb_ops *cb_ops, void *cb_arg) { struct request_ctx *request; struct bufferevent *bev; if ((request = malloc(sizeof(*request))) == NULL) { cb_ops->done("Out of memory", cb_arg); return; } memset(request, 0, sizeof(*request)); request->method = method; request->host = host; request->port = port; request->path = path; request->access_token = access_token; setup_request_body(request, body); request->cb_ops = cb_ops; request->cb_arg = cb_arg; request->conn_stash = https->conn_stash; bev = conn_stash_get_bev(https->conn_stash, host, port); if (bev == NULL) { cb_ops->done("Failed to set up connection", cb_arg); free(request); return; } bufferevent_setcb(bev, cb_read, cb_write, cb_event, request); submit_request(bev, request); }
static void do_request_test (SoupSession *session, SoupURI *base_uri, RequestTestFlags flags) { SoupURI *uri = base_uri; PutTestData ptd; SoupMessage *msg; const char *client_md5, *server_md5; GChecksum *check; int i, length; debug_printf (1, "PUT"); if (flags & HACKY_STREAMING) debug_printf (1, " w/ hacky streaming"); else if (flags & PROPER_STREAMING) debug_printf (1, " w/ proper streaming"); if (flags & RESTART) { debug_printf (1, " and restart"); uri = soup_uri_copy (base_uri); soup_uri_set_path (uri, "/redirect"); } debug_printf (1, "\n"); ptd.session = session; setup_request_body (&ptd); ptd.streaming = flags & (HACKY_STREAMING | PROPER_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 (flags & HACKY_STREAMING) { g_signal_connect (msg, "wrote_chunk", G_CALLBACK (write_next_chunk_streaming_hack), &ptd); if (flags & RESTART) { g_signal_connect (msg, "restarted", G_CALLBACK (restarted_streaming_hack), &ptd); } } else { g_signal_connect (msg, "wrote_chunk", G_CALLBACK (write_next_chunk), &ptd); } if (flags & PROPER_STREAMING) { soup_message_set_flags (msg, SOUP_MESSAGE_CAN_REBUILD); if (flags & RESTART) { g_signal_connect (msg, "restarted", G_CALLBACK (restarted_streaming), &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); }