As you noted in your StackOverflow post, it's important that you don't mistake a CONNECT request for a regular HTTP request.
You can do this using the following in your BeforeRequest handler:
if (oSession.HTTPMethodIs("CONNECT")) {
return;
}
Your sample code uses a very broad lock() statement in the BeforeRequest handler which will impede your throughput. You should scope down that lock statement such that its body includes only the statements that need to be serialized.
Your code also seems to assume that HTTP request bodies will always be ASCII, which isn't a safe assumption in general, although it might be okay for your scenario.