wasSharp

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 17  →  ?path2? @ 18
File deleted
\ No newline at end of file
/Web/Utilities/Extensions.cs
/Web/Utilities/WebExtensions.cs
@@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html for legal details, //
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
using System.Linq;
using System.Linq.Expressions;
using System.Net;
using System.Text.RegularExpressions;
 
namespace wasSharp.Web.Utilities
{
public static class WebExtensions
{
private static readonly Func<string, string> directURIEscapeDataString =
((Expression<Func<string, string>>)
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766).AsParallel()
.Select(o => Uri.EscapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - o*32766))))
.ToArray()))).Compile();
 
private static readonly Func<string, string> directURIUnescapeDataString =
((Expression<Func<string, string>>)
(data => string.Join("", Enumerable.Range(0, (data.Length + 32765)/32766).AsParallel()
.Select(
o => Uri.UnescapeDataString(data.Substring(o*32766, Math.Min(32766, data.Length - o*32766))))
.ToArray()))).Compile();
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>RFC3986 URI Escapes a string</summary>
/// <remarks>
/// data - a string to escape
/// </remarks>
/// <returns>an RFC3986 escaped string</returns>
public static string URIEscapeDataString(this string data)
{
return directURIEscapeDataString(data);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>URI unescapes an RFC3986 URI escaped string</summary>
/// <remarks>
/// data - a string to unescape
/// </remarks>
/// <returns>the resulting string</returns>
public static string URIUnescapeDataString(this string data)
{
return directURIUnescapeDataString(data);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>RFC1738 URL Escapes a string</summary>
/// <param name="data">a string to escape</param>
/// <returns>an RFC1738 escaped string</returns>
public static string URLEscapeDataString(this string data)
{
return WebUtility.UrlEncode(data);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <summary>RFC1738 URL Unescape a string</summary>
/// <param name="data">a string to unescape</param>
/// <returns>an RFC1738 unescaped string</returns>
public static string URLUnescapeDataString(this string data)
{
return WebUtility.UrlDecode(data);
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) Wizardry and Steamworks 2015 - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
/// <param name="prefix">a HttpListener prefix</param>
/// <returns>the port of the HttpListener</returns>
public static long GetPortFromPrefix(this string prefix)
{
var split = Regex.Replace(
prefix,
@"^([a-zA-Z]+:\/\/)?([^\/]+)\/.*?$",
"$2"
).Split(':');
long port;
return split.Length <= 1 || !long.TryParse(split[1], out port) ? 80 : port;
}
}
}
/Web/wasHTTPClient.cs
@@ -65,11 +65,10 @@
}
// 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)
{
case false:
headers = new Dictionary<string, string> {{"Accept", @"*/*"}, {"Accept-Encoding", "gzip,defalate"}};
headers = new Dictionary<string, string> {{"Accept", @"*/*"}};
break;
default:
if (!headers.ContainsKey("Accept"))
@@ -76,10 +75,6 @@
{
headers.Add("Accept", @"*/*");
}
if (!headers.ContainsKey("Accept-Encoding"))
{
headers.Add("Accept-Encoding", "gzip,deflate");
}
break;
}
foreach (var header in headers)
@@ -119,15 +114,10 @@
}
// 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
@@ -173,15 +163,10 @@
}
// 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