wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 16  →  ?path2? @ 17
/Web/wasHTTPClient.cs
@@ -11,6 +11,7 @@
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using wasSharp.Collections.Utilities;
 
namespace wasSharp.Web
{
@@ -62,13 +63,29 @@
{
HTTPClient.DefaultRequestHeaders.Authorization = authentication;
}
if (headers != null)
// Add some standard headers:
// Accept - for socially acceptable security of mod_sec
// Accept-Encoding - since we want to use compression if possible
switch (headers != null)
{
foreach (var header in headers)
{
HTTPClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}
case false:
headers = new Dictionary<string, string> {{"Accept", @"*/*"}, {"Accept-Encoding", "gzip,defalate"}};
break;
default:
if (!headers.ContainsKey("Accept"))
{
headers.Add("Accept", @"*/*");
}
if (!headers.ContainsKey("Accept-Encoding"))
{
headers.Add("Accept-Encoding", "gzip,deflate");
}
break;
}
foreach (var header in headers)
{
HTTPClient.DefaultRequestHeaders.Add(header.Key, header.Value);
}
HTTPClient.Timeout = TimeSpan.FromMilliseconds(timeout);
MediaType = mediaType;
}
@@ -100,6 +117,17 @@
{
request.Headers.Add(header.Key, header.Value);
}
// Add some standard headers:
// Accept - for socially acceptable security of mod_sec
// Accept-Encoding - since we want to use compression if possible
if (!headers.ContainsKey("Accept"))
{
headers.Add("Accept", @"*/*");
}
if (!headers.ContainsKey("Accept-Encoding"))
{
headers.Add("Accept-Encoding", "gzip,deflate");
}
using (var response = await HTTPClient.SendAsync(request))
{
return response.IsSuccessStatusCode
@@ -143,6 +171,17 @@
{
request.Headers.Add(header.Key, header.Value);
}
// Add some standard headers:
// Accept - for socially acceptable security of mod_sec
// Accept-Encoding - since we want to use compression if possible
if (!headers.ContainsKey("Accept"))
{
headers.Add("Accept", @"*/*");
}
if (!headers.ContainsKey("Accept-Encoding"))
{
headers.Add("Accept-Encoding", "gzip,deflate");
}
using (var response = await HTTPClient.SendAsync(request))
{
return response.IsSuccessStatusCode
@@ -292,8 +331,7 @@
 
public void Dispose()
{
if (HTTPClient != null)
HTTPClient.Dispose();
HTTPClient?.Dispose();
}
}
}