/// <summary> /// Perform the WebDAV call and fire the callback when finished. /// </summary> /// <param name="uri"></param> /// <param name="headers"></param> /// <param name="method"></param> /// <param name="content"></param> private async Task <HttpResponseMessage> HttpUploadRequest(Uri uri, HttpMethod method, Stream content, IDictionary <string, string> headers = null) { using (var request = new HttpRequestMessage(method, uri)) { request.Headers.Connection.Add("Keep-Alive"); if (!string.IsNullOrWhiteSpace(UserAgent)) { request.Headers.UserAgent.Add(new ProductInfoHeaderValue(UserAgent, UserAgentVersion)); } else { request.Headers.UserAgent.Add(new ProductInfoHeaderValue("WebDAVClient", AssemblyVersion)); } if (headers != null) { foreach (string key in headers.Keys) { request.Headers.Add(key, headers[key]); } } // Need to send along content? if (content != null) { request.Content = new StreamContent(content); } return(await _httpClientWrapper.SendUploadAsync(request).ConfigureAwait(false)); } }
/// <summary> /// Perform the WebDAV call and fire the callback when finished. /// </summary> /// <param name="uri"></param> /// <param name="headers"></param> /// <param name="method"></param> /// <param name="content"></param> private async Task <HttpResponseMessage> HttpUploadRequest(Uri uri, HttpMethod method, Stream content, IDictionary <string, string> headers = null, long?startbytes = null, long?endbytes = null, long?totalLength = null) { using (var request = new HttpRequestMessage(method, uri)) { request.Headers.Connection.Add("Keep-Alive"); if (!string.IsNullOrWhiteSpace(UserAgent)) { request.Headers.UserAgent.Add(new ProductInfoHeaderValue(UserAgent, UserAgentVersion)); } else { request.Headers.UserAgent.Add(new ProductInfoHeaderValue("WebDAVClient", AssemblyVersion)); } if (headers != null) { foreach (string key in headers.Keys) { request.Headers.Add(key, headers[key]); } } // Need to send along content? if (content != null) { request.Content = new StreamContent(content); if (startbytes.HasValue && endbytes.HasValue) { var len = totalLength.HasValue ? totalLength.ToString() : "*"; request.Content.Headers.ContentRange = ContentRangeHeaderValue.Parse($"bytes {startbytes}-{endbytes}/{len}"); request.Content.Headers.ContentLength = endbytes - startbytes + 1; } } return(await _httpClientWrapper.SendUploadAsync(request).ConfigureAwait(false)); } }