Forked from gareth-cheeseman/HTMLParsingPlugin.cs
Created
September 14, 2021 03:13
-
-
Save Maghaen/fa489f92297691d79ad732039afe075e to your computer and use it in GitHub Desktop.
HTMLParsingPlugin for use with VS loadtesting. Must be file in main solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Configuration; | |
using System.Reflection; | |
using Microsoft.VisualStudio.TestTools.LoadTesting; | |
namespace Tests | |
{ | |
public class HMTLParsingPlugin : ILoadTestPlugin | |
{ | |
public void Initialize(LoadTest loadTest) | |
{ | |
ToggleAllowUnsafeHeaderParsing(true); | |
} | |
public static bool ToggleAllowUnsafeHeaderParsing(bool enable) | |
{ | |
//Get the assembly that contains the internal class | |
Assembly assembly = Assembly.GetAssembly(typeof(SettingsSection)); | |
if (assembly != null) | |
{ | |
//Use the assembly in order to get the internal type for the internal class | |
Type settingsSectionType = assembly.GetType("System.Net.Configuration.SettingsSectionInternal"); | |
if (settingsSectionType != null) | |
{ | |
//Use the internal static property to get an instance of the internal settings class. | |
//If the static instance isn't created already invoking the property will create it for us. | |
object anInstance = settingsSectionType.InvokeMember("Section", | |
BindingFlags.Static | BindingFlags.GetProperty | BindingFlags.NonPublic, null, null, new object[] { }); | |
if (anInstance != null) | |
{ | |
//Locate the private bool field that tells the framework if unsafe header parsing is allowed | |
FieldInfo aUseUnsafeHeaderParsing = settingsSectionType.GetField("useUnsafeHeaderParsing", BindingFlags.NonPublic | BindingFlags.Instance); | |
if (aUseUnsafeHeaderParsing != null) | |
{ | |
aUseUnsafeHeaderParsing.SetValue(anInstance, enable); | |
return true; | |
} | |
} | |
} | |
} | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment