diff options
author | Sean Templeton <seantempleton@outlook.com> | 2019-02-18 04:28:56 +0300 |
---|---|---|
committer | Sean Templeton <seantempleton@outlook.com> | 2019-03-06 06:08:26 +0300 |
commit | c3472823de5b0a2856c609a1317e46b1dc360972 (patch) | |
tree | 5a3ae83ed98e0e6659cc63cf014b4f739a213d9b /Duplicati/Library/Backend | |
parent | 7843f837a476f34b69f63a1ad25b4223b90abd70 (diff) |
Update HubiC and OpenStack backends for async Put
Diffstat (limited to 'Duplicati/Library/Backend')
-rw-r--r-- | Duplicati/Library/Backend/HubiC/HubiCBackend.cs | 6 | ||||
-rw-r--r-- | Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs | 21 | ||||
-rw-r--r-- | Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs | 17 |
3 files changed, 25 insertions, 19 deletions
diff --git a/Duplicati/Library/Backend/HubiC/HubiCBackend.cs b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs index f6ece03d6..9fbc90d5c 100644 --- a/Duplicati/Library/Backend/HubiC/HubiCBackend.cs +++ b/Duplicati/Library/Backend/HubiC/HubiCBackend.cs @@ -108,8 +108,7 @@ namespace Duplicati.Library.Backend.HubiC public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
{
- m_openstack.Put(remotename, stream, cancelToken);
- return Task.FromResult(true);
+ return m_openstack.Put(remotename, stream, cancelToken);
}
public void Get(string remotename, System.IO.Stream stream)
@@ -128,8 +127,7 @@ namespace Duplicati.Library.Backend.HubiC public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
- m_openstack.Put(remotename, filename, cancelToken);
- return Task.FromResult(true);
+ return m_openstack.Put(remotename, filename, cancelToken);
}
public void Get(string remotename, string filename)
diff --git a/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs b/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs index bcfbca60c..ba0b7acb6 100644 --- a/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs +++ b/Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs @@ -330,7 +330,7 @@ namespace Duplicati.Library {
if (requestdata is string)
throw new ArgumentException("Cannot send string object as data");
-
+
if (method == null && requestdata != null)
method = "POST";
@@ -355,7 +355,7 @@ namespace Duplicati.Library if (string.IsNullOrEmpty(req.Request.ContentType))
req.Request.ContentType = "application/octet-stream";
- using(var rs = req.GetRequestStream())
+ using (var rs = req.GetRequestStream())
Library.Utility.Utility.CopyStream(stream, rs);
}
else
@@ -364,20 +364,32 @@ namespace Duplicati.Library req.Request.ContentLength = data.Length;
req.Request.ContentType = "application/json; charset=UTF-8";
- using(var rs = req.GetRequestStream())
+ using (var rs = req.GetRequestStream())
rs.Write(data, 0, data.Length);
}
}
return (HttpWebResponse)req.GetResponse();
}
- catch(Exception ex)
+ catch (Exception ex)
{
ParseException(ex);
throw;
}
}
+ public async Task<HttpWebResponse> GetResponseAsync(string url, CancellationToken cancelToken, object requestdata = null, string method = null)
+ {
+ if (requestdata is string)
+ throw new ArgumentException("Cannot send string object as data");
+
+ if (method == null && requestdata != null)
+ method = "POST";
+
+ var areq = new AsyncHttpRequest(CreateRequest(url, method));
+ return await GetResponseAsync(areq, cancelToken, requestdata).ConfigureAwait(false);
+ }
+
public async Task<HttpWebResponse> GetResponseAsync(AsyncHttpRequest req, CancellationToken cancelToken, object requestdata = null)
{
try
@@ -426,4 +438,3 @@ namespace Duplicati.Library }
}
}
-
diff --git a/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs b/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs index 1e3840e32..1b07f9c68 100644 --- a/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs +++ b/Duplicati/Library/Backend/OpenStack/OpenStackStorage.cs @@ -485,17 +485,16 @@ namespace Duplicati.Library.Backend.OpenStack }
#region IStreamingBackend implementation
- public Task Put(string remotename, System.IO.Stream stream, CancellationToken cancelToken)
+ public async Task Put(string remotename, Stream stream, CancellationToken cancelToken)
{
- var url = JoinUrls(SimpleStorageEndPoint, m_container, Library.Utility.Uri.UrlPathEncode(m_prefix + remotename));
- using(m_helper.GetResponse(url, stream, "PUT"))
+ var url = JoinUrls(SimpleStorageEndPoint, m_container, Utility.Uri.UrlPathEncode(m_prefix + remotename));
+ using(await m_helper.GetResponseAsync(url, cancelToken, stream, "PUT"))
{ }
-
- return Task.FromResult(true);
}
- public void Get(string remotename, System.IO.Stream stream)
+
+ public void Get(string remotename, Stream stream)
{
- var url = JoinUrls(SimpleStorageEndPoint, m_container, Library.Utility.Uri.UrlPathEncode(m_prefix + remotename));
+ var url = JoinUrls(SimpleStorageEndPoint, m_container, Utility.Uri.UrlPathEncode(m_prefix + remotename));
try
{
@@ -569,9 +568,7 @@ namespace Duplicati.Library.Backend.OpenStack public Task Put(string remotename, string filename, CancellationToken cancelToken)
{
using (FileStream fs = File.OpenRead(filename))
- Put(remotename, fs, cancelToken);
-
- return Task.FromResult(true);
+ return Put(remotename, fs, cancelToken);
}
public void Get(string remotename, string filename)
|