New WebTest Plugin: "Force UrlEncoded Cookies"
Showing
1 changed file
with
33 additions
and
0 deletions
... | @@ -20,9 +20,42 @@ using System.Text.RegularExpressions; | ... | @@ -20,9 +20,42 @@ using System.Text.RegularExpressions; |
20 | using System.IO; | 20 | using System.IO; |
21 | using System.IO.Compression; | 21 | using System.IO.Compression; |
22 | using Microsoft.VisualStudio.TestTools.LoadTesting; | 22 | using Microsoft.VisualStudio.TestTools.LoadTesting; |
23 | using System.Net; | ||
23 | 24 | ||
24 | namespace LIL_VSTT_Plugins | 25 | namespace LIL_VSTT_Plugins |
25 | { | 26 | { |
27 | [DisplayName("Force UrlEncoded Cookies")] | ||
28 | [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.")] | ||
29 | public class DebugCookies : WebTestPlugin | ||
30 | { | ||
31 | public override void PostRequest(object sender, PostRequestEventArgs e) | ||
32 | { | ||
33 | if (e.ResponseExists) | ||
34 | { | ||
35 | for (int i = 0; i < e.Response.Headers.Count; i++) | ||
36 | { | ||
37 | if (e.Response.Headers.Keys[i].Equals("Set-Cookie")) | ||
38 | { | ||
39 | try | ||
40 | { | ||
41 | System.Net.CookieContainer cc = new System.Net.CookieContainer(); | ||
42 | cc.SetCookies(e.Response.ResponseUri, e.Response.Headers[i]); | ||
43 | foreach (Cookie c in cc.GetCookies(e.Response.ResponseUri)) | ||
44 | { | ||
45 | c.Value = WebUtility.UrlEncode(WebUtility.UrlDecode(c.Value)); | ||
46 | e.WebTest.Context.CookieContainer.Add(c); | ||
47 | } | ||
48 | } | ||
49 | catch (Exception ex) | ||
50 | { | ||
51 | e.WebTest.AddCommentToResult("Set-Cookie: Exception: " + ex.Message); | ||
52 | } | ||
53 | } | ||
54 | } | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | |||
26 | [DisplayName("Add Session Cookie")] | 59 | [DisplayName("Add Session Cookie")] |
27 | [Description("Adds a cookie to the webtest cookie collection for this request and all remaining requests in this session.")] | 60 | [Description("Adds a cookie to the webtest cookie collection for this request and all remaining requests in this session.")] |
28 | public class AddSessionCookie : WebTestRequestPlugin | 61 | public class AddSessionCookie : WebTestRequestPlugin | ... | ... |
-
Please register or sign in to post a comment