Commit 80f74fe6 80f74fe6245b3fe3728a74305a72ac98d1452c6b by Christian Gerdes

New WebTest Plugin: "Force UrlEncoded Cookies"

1 parent 70840838
......@@ -20,9 +20,42 @@ using System.Text.RegularExpressions;
using System.IO;
using System.IO.Compression;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using System.Net;
namespace LIL_VSTT_Plugins
{
[DisplayName("Force UrlEncoded Cookies")]
[Description("Reparses all cookies set by the server and stores the value in UrlEncoded format. Cookies with illegal characters will otherwise cause none of the previous set cookies to be added to new requests.")]
public class DebugCookies : WebTestPlugin
{
public override void PostRequest(object sender, PostRequestEventArgs e)
{
if (e.ResponseExists)
{
for (int i = 0; i < e.Response.Headers.Count; i++)
{
if (e.Response.Headers.Keys[i].Equals("Set-Cookie"))
{
try
{
System.Net.CookieContainer cc = new System.Net.CookieContainer();
cc.SetCookies(e.Response.ResponseUri, e.Response.Headers[i]);
foreach (Cookie c in cc.GetCookies(e.Response.ResponseUri))
{
c.Value = WebUtility.UrlEncode(WebUtility.UrlDecode(c.Value));
e.WebTest.Context.CookieContainer.Add(c);
}
}
catch (Exception ex)
{
e.WebTest.AddCommentToResult("Set-Cookie: Exception: " + ex.Message);
}
}
}
}
}
}
[DisplayName("Add Session Cookie")]
[Description("Adds a cookie to the webtest cookie collection for this request and all remaining requests in this session.")]
public class AddSessionCookie : WebTestRequestPlugin
......