web::http::http_request delete_message(const cloud_queue& queue, const cloud_queue_message& message, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
    {
        uri_builder.append_query(U("popreceipt"), message.pop_receipt());

        web::http::http_request request = queue_base_request(web::http::methods::DEL, uri_builder, timeout, context);
        return request;
    }
    web::http::http_request update_message(const cloud_queue& queue, const cloud_queue_message& message, std::chrono::seconds visibility_timeout, bool update_contents, web::http::uri_builder uri_builder, const std::chrono::seconds& timeout, operation_context context)
    {
        uri_builder.append_query(U("popreceipt"), message.pop_receipt());
        uri_builder.append_query(U("visibilitytimeout"), visibility_timeout.count());

        web::http::http_request request = queue_base_request(web::http::methods::PUT, uri_builder, timeout, context);

        if (update_contents)
        {
            protocol::message_writer writer;
            std::string content = writer.write(message.content_as_string());
            request.set_body(content);
        }

        return request;
    }
    web::http::http_request update_message(const cloud_queue_message& message, std::chrono::seconds visibility_timeout, bool update_contents, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context)
    {
        uri_builder.append_query(core::make_query_parameter(_XPLATSTR("popreceipt"), message.pop_receipt()));
        uri_builder.append_query(core::make_query_parameter(_XPLATSTR("visibilitytimeout"), visibility_timeout.count(), /* do_encoding */ false));

        web::http::http_request request = queue_base_request(web::http::methods::PUT, uri_builder, timeout, context);

        if (update_contents)
        {
            protocol::message_writer writer;
            std::string content = writer.write(message);
            request.set_body(content);
        }

        return request;
    }
    pplx::task<void> cloud_queue::update_message_async(cloud_queue_message& message, std::chrono::seconds visibility_timeout, bool update_content, queue_request_options& options, operation_context context)
    {
        if (message.id().empty())
        {
            throw std::invalid_argument(protocol::error_empty_message_id);
        }

        if (message.pop_receipt().empty())
        {
            throw std::invalid_argument(protocol::error_empty_message_pop_receipt);
        }

        if (visibility_timeout.count() < 0LL)
        {
            throw std::invalid_argument(protocol::error_negative_visibility_timeout);
        }

        if (visibility_timeout.count() > 604800LL)
        {
            throw std::invalid_argument(protocol::error_large_visibility_timeout);
        }

        queue_request_options modified_options = get_modified_options(options);
        storage_uri uri = protocol::generate_queue_message_uri(service_client(), *this, message);

        std::shared_ptr<core::storage_command<void>> command = std::make_shared<core::storage_command<void>>(uri);
        command->set_build_request(std::bind(protocol::update_message, message, visibility_timeout, update_content, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
        command->set_authentication_handler(service_client().authentication_handler());
        command->set_preprocess_response([&message] (const web::http::http_response& response, const request_result& result, operation_context context) mutable
        {
            protocol::preprocess_response_void(response, result, context);
            message.set_pop_receipt(protocol::parse_pop_receipt(response));
            message.set_next_visible_time(protocol::parse_next_visible_time(response));
        });
        return core::executor<void>::execute_async(command, modified_options, context);
    }