Trying to setup a proxy but getting 500 error in browser
<p>I'm creating a custom proxy that is currently setup on my local machine to intercept CNN.com. I have the browsers successfully hitting my proxy, the request is sent, I get a response, and it is a 200 OK response complete with a valid HTML payload. I have used Wireshark to verify the request => CNN and the initial response is identical from when I have the proxy turned on and when I'm hitting the site directly.</p>

<p>The HttpWebRequest looks like such before being sent:</p>

<pre><code>2016-06-30 20:23:11.7870 INFO Getting response for request
2016-06-30 20:23:11.7870 DEBUG this.AllowAutoRedirect = True
2016-06-30 20:23:11.7870 DEBUG this.AllowWriteStreamBuffering = True
2016-06-30 20:23:11.7870 DEBUG this.AllowReadStreamBuffering = False
2016-06-30 20:23:11.7960 DEBUG this.HaveResponse = False
2016-06-30 20:23:11.7960 DEBUG this.KeepAlive = True
2016-06-30 20:23:11.7960 DEBUG this.Pipelined = True
2016-06-30 20:23:11.7960 DEBUG this.PreAuthenticate = False
2016-06-30 20:23:11.7960 DEBUG this.UnsafeAuthenticatedConnectionSharing = False
2016-06-30 20:23:11.7960 DEBUG this.SendChunked = False
2016-06-30 20:23:11.7960 DEBUG this.AutomaticDecompression = None
2016-06-30 20:23:11.7960 DEBUG this.DefaultCachePolicy.Level = BypassCache
2016-06-30 20:23:11.7960 DEBUG this.DefaultMaximumResponseHeadersLength = 64
2016-06-30 20:23:11.7960 DEBUG this.DefaultMaximumErrorResponseLength = 64
2016-06-30 20:23:11.7960 DEBUG this.MaximumResponseHeadersLength = 64
2016-06-30 20:23:11.7960 DEBUG this.ClientCertificates.Capacity = 4
2016-06-30 20:23:11.7960 DEBUG this.ClientCertificates.Count = 1
2016-06-30 20:23:11.7960 DEBUG this.CookieContainer.Capacity = 300
2016-06-30 20:23:11.7960 DEBUG this.CookieContainer.Count = 14
2016-06-30 20:23:11.7960 DEBUG this.CookieContainer.MaxCookieSize = 4096
2016-06-30 20:23:11.7960 DEBUG this.CookieContainer.PerDomainCapacity = 20
2016-06-30 20:23:11.7960 DEBUG this.SupportsCookieContainer = True
2016-06-30 20:23:11.7960 DEBUG this.RequestUri.AbsolutePath = /
2016-06-30 20:23:11.7960 DEBUG this.RequestUri.AbsoluteUri = http://151.101.44.73/
2016-06-30 20:23:11.7960 DEBUG this.RequestUri.LocalPath = /
2016-06-30 20:23:11.7960 DEBUG this.RequestUri.Authority = 151.101.44.73
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.HostNameType = IPv4
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.IsDefaultPort = True
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.IsFile = False
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.IsLoopback = False
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.PathAndQuery = /
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Segments[0] = /
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.IsUnc = False
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Host = 151.101.44.73
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Port = 80
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Query = 
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Fragment = 
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.Scheme = http
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.OriginalString = http://151.101.44.73/
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.DnsSafeHost = 151.101.44.73
2016-06-30 20:23:11.8120 DEBUG this.RequestUri.IdnHost = 151.101.44.73
2016-06-30 20:23:11.8290 DEBUG this.RequestUri.IsAbsoluteUri = True
2016-06-30 20:23:11.8290 DEBUG this.RequestUri.UserEscaped = False
2016-06-30 20:23:11.8290 DEBUG this.RequestUri.UserInfo = 
2016-06-30 20:23:11.8290 DEBUG this.ContentLength = 0
2016-06-30 20:23:11.8290 DEBUG this.Timeout = 100000
2016-06-30 20:23:11.8290 DEBUG this.ReadWriteTimeout = 300000
2016-06-30 20:23:11.8290 DEBUG this.ContinueTimeout = 350
2016-06-30 20:23:11.8290 DEBUG this.Address.AbsolutePath = /
2016-06-30 20:23:11.8290 DEBUG this.Address.AbsoluteUri = http://151.101.44.73/
2016-06-30 20:23:11.8290 DEBUG this.Address.LocalPath = /
2016-06-30 20:23:11.8290 DEBUG this.Address.Authority = 151.101.44.73
2016-06-30 20:23:11.8290 DEBUG this.Address.HostNameType = IPv4
2016-06-30 20:23:11.8290 DEBUG this.Address.IsDefaultPort = True
2016-06-30 20:23:11.8290 DEBUG this.Address.IsFile = False
2016-06-30 20:23:11.8290 DEBUG this.Address.IsLoopback = False
2016-06-30 20:23:11.8290 DEBUG this.Address.PathAndQuery = /
2016-06-30 20:23:11.8290 DEBUG this.Address.Segments[0] = /
2016-06-30 20:23:11.8290 DEBUG this.Address.IsUnc = False
2016-06-30 20:23:11.8431 DEBUG this.Address.Host = 151.101.44.73
2016-06-30 20:23:11.8431 DEBUG this.Address.Port = 80
2016-06-30 20:23:11.8431 DEBUG this.Address.Query = 
2016-06-30 20:23:11.8431 DEBUG this.Address.Fragment = 
2016-06-30 20:23:11.8431 DEBUG this.Address.Scheme = http
2016-06-30 20:23:11.8431 DEBUG this.Address.OriginalString = http://151.101.44.73/
2016-06-30 20:23:11.8431 DEBUG this.Address.DnsSafeHost = 151.101.44.73
2016-06-30 20:23:11.8431 DEBUG this.Address.IdnHost = 151.101.44.73
2016-06-30 20:23:11.8431 DEBUG this.Address.IsAbsoluteUri = True
2016-06-30 20:23:11.8431 DEBUG this.Address.UserEscaped = False
2016-06-30 20:23:11.8431 DEBUG this.Address.UserInfo = 
2016-06-30 20:23:11.8431 DEBUG this.ContinueDelegate = null
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.BindIPEndPointDelegate = null
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.ConnectionLeaseTimeout = -1
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.Address.AbsolutePath = /
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.Address.AbsoluteUri = http://151.101.44.73/
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.Address.LocalPath = /
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.Address.Authority = 151.101.44.73
2016-06-30 20:23:11.8431 DEBUG this.ServicePoint.Address.HostNameType = IPv4
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IsDefaultPort = True
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IsFile = False
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IsLoopback = False
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.PathAndQuery = /
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Segments[0] = /
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IsUnc = False
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Host = 151.101.44.73
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Port = 80
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Query = 
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Fragment = 
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.Scheme = http
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.OriginalString = http://151.101.44.73/
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.DnsSafeHost = 151.101.44.73
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IdnHost = 151.101.44.73
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.IsAbsoluteUri = True
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.UserEscaped = False
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Address.UserInfo = 
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.MaxIdleTime = 100000
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.UseNagleAlgorithm = True
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.ReceiveBufferSize = -1
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.Expect100Continue = True
2016-06-30 20:23:11.8591 DEBUG this.ServicePoint.IdleSince = 6/30/2016 8:23:11 PM
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.ProtocolVersion = 1.1
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.ConnectionName = http
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.ConnectionLimit = 2147483647
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.CurrentConnections = 0
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.Certificate = null
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.ClientCertificate = null
2016-06-30 20:23:11.8741 DEBUG this.ServicePoint.SupportsPipelining = True
2016-06-30 20:23:11.8741 DEBUG this.Host = www.cnn.com
2016-06-30 20:23:11.8741 DEBUG this.MaximumAutomaticRedirections = 50
2016-06-30 20:23:11.8741 DEBUG this.Method = GET
2016-06-30 20:23:11.8741 DEBUG this.Credentials.UserName = 
2016-06-30 20:23:11.8741 DEBUG this.Credentials.Password = 
2016-06-30 20:23:11.8741 DEBUG this.Credentials.SecurePassword = System.Security.SecureString
2016-06-30 20:23:11.8741 DEBUG this.Credentials.Domain = 
2016-06-30 20:23:11.8741 DEBUG this.UseDefaultCredentials = True
2016-06-30 20:23:11.8741 DEBUG this.ConnectionGroupName = null
2016-06-30 20:23:11.8741 DEBUG this.Headers.Count = 4
2016-06-30 20:23:11.8741 DEBUG this.Headers.Keys.Count = 4
2016-06-30 20:23:11.8741 DEBUG this.Headers.AllKeys[0] = Accept
2016-06-30 20:23:11.8741 DEBUG this.Headers.AllKeys[1] = User-Agent
2016-06-30 20:23:11.8741 DEBUG this.Headers.AllKeys[2] = Accept-Encoding
2016-06-30 20:23:11.8741 DEBUG this.Headers.AllKeys[3] = Accept-Language
2016-06-30 20:23:11.8901 DEBUG this.Proxy.Credentials = null
2016-06-30 20:23:11.8901 DEBUG this.ProtocolVersion = 1.1
2016-06-30 20:23:11.8901 DEBUG this.ContentType = null
2016-06-30 20:23:11.8901 DEBUG this.MediaType = null
2016-06-30 20:23:11.8901 DEBUG this.TransferEncoding = null
2016-06-30 20:23:11.8901 DEBUG this.Connection = null
2016-06-30 20:23:11.8901 DEBUG this.Accept = text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
2016-06-30 20:23:11.8901 DEBUG this.Referer = null
2016-06-30 20:23:11.8901 DEBUG this.UserAgent = Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
2016-06-30 20:23:11.8901 DEBUG this.Expect = null
2016-06-30 20:23:11.8901 DEBUG this.IfModifiedSince = 1/1/0001 12:00:00 AM
2016-06-30 20:23:11.8901 DEBUG this.Date = 1/1/0001 12:00:00 AM
2016-06-30 20:23:11.8901 DEBUG this.ServerCertificateValidationCallback = null
2016-06-30 20:23:11.8901 DEBUG this.CachePolicy.Level = BypassCache
2016-06-30 20:23:11.8901 DEBUG this.AuthenticationLevel = None
2016-06-30 20:23:11.8901 DEBUG this.ImpersonationLevel = Delegation
</code></pre>

<p>I am translating and writing the response which looks like so:</p>

<pre><code>2016-06-30 20:04:01.3221 INFO Sending the following response headers to the host
 x-servedByHost =&gt; prd-10-60-165-23.nodes.56m.dmtio.net
 X-XSS-Protection =&gt; 1; mode=block
 Content-Security-Policy =&gt; default-src 'self' http://*.cnn.com:* https://*.cnn.com:* *.cnn.net:* *.turner.com:* *.ugdturner.com:* *.vgtf.net:*; script-src 'unsafe-inline' 'unsafe-eval' 'self' *; style-src 'unsafe-inline' 'self' *; frame-src 'self' *; object-src 'self' *; img-src 'self' * data: blob:; media-src 'self' *; font-src 'self' *; connect-src 'self' *;
 Access-Control-Allow-Origin =&gt; *
 Fastly-Debug-Digest =&gt; 1e206303e0672a50569b0c0a29903ca81f3ef5033de74682ce90ec9d13686981
 Accept-Ranges =&gt; bytes
 Cache-Control =&gt; max-age=60
 Content-Type =&gt; text/html; charset=utf-8
 Date =&gt; Thu, 30 Jun 2016 23:47:34 GMT
 Via =&gt; 1.1 varnish,1.1 varnish
 Age =&gt; 261
 Connection =&gt; keep-alive
 Set-Cookie =&gt; countryCode=US; Domain=.cnn.com
 X-Served-By =&gt; cache-iad2133-IAD, cache-ord1732-ORD
 X-Cache =&gt; HIT, HIT
 X-Cache-Hits =&gt; 1, 246
 X-Timer =&gt; S1467330454.559495,VS0,VE0
 Vary =&gt; Accept-Encoding
 Transfer-Encoding =&gt; chunked
2016-06-30 20:05:20.3758 INFO Writing response to outbound stream
2016-06-30 20:05:29.1606 INFO Request and response complete
2016-06-30 20:05:29.7949 DEBUG this.HeadersWritten = True
2016-06-30 20:05:29.7959 DEBUG this.SupportsAsyncFlush = True
2016-06-30 20:05:29.7959 DEBUG this.Cookies = System.Web.HttpCookieCollection
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[0] = x-servedByHost
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[1] = X-XSS-Protection
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[2] = Content-Security-Policy
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[3] = Access-Control-Allow-Origin
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[4] = Fastly-Debug-Digest
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[5] = Accept-Ranges
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[6] = Cache-Control
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[7] = Content-Type
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[8] = Date
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[9] = Via
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[10] = Age
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[11] = Connection
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[12] = Set-Cookie
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[13] = X-Served-By
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[14] = X-Cache
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[15] = X-Cache-Hits
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[16] = X-Timer
2016-06-30 20:05:29.7959 DEBUG this.Headers.AllKeys[17] = Vary
2016-06-30 20:05:29.8119 DEBUG this.Headers.AllKeys[18] = Transfer-Encoding
2016-06-30 20:05:29.8119 DEBUG this.Headers.AllKeys[19] = X-AspNet-Version
2016-06-30 20:05:29.8119 DEBUG this.Headers.Count = 20
2016-06-30 20:05:29.8119 DEBUG this.Headers.Keys.Count = 20
2016-06-30 20:05:29.8119 DEBUG this.StatusCode = 200
2016-06-30 20:05:29.8119 DEBUG this.SubStatusCode = 0
2016-06-30 20:05:29.8119 DEBUG this.StatusDescription = OK
2016-06-30 20:05:29.8119 DEBUG this.TrySkipIisCustomErrors = False
2016-06-30 20:05:29.8119 DEBUG this.SuppressFormsAuthenticationRedirect = False
2016-06-30 20:05:29.8119 DEBUG this.SuppressDefaultCacheControlHeader = False
2016-06-30 20:05:29.8119 DEBUG this.BufferOutput = True
2016-06-30 20:05:29.8119 DEBUG this.ContentType = text/html
2016-06-30 20:05:29.8119 DEBUG this.Charset = utf-8
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.BodyName = utf-8
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.EncodingName = Unicode (UTF-8)
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.HeaderName = utf-8
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.WebName = utf-8
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.WindowsCodePage = 1200
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.IsBrowserDisplay = True
2016-06-30 20:05:29.8119 DEBUG this.ContentEncoding.IsBrowserSave = True
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.IsMailNewsDisplay = True
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.IsMailNewsSave = True
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.IsSingleByte = False
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.EncoderFallback = System.Text.EncoderReplacementFallback
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.DecoderFallback = System.Text.DecoderReplacementFallback
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.IsReadOnly = True
2016-06-30 20:05:29.8279 DEBUG this.ContentEncoding.CodePage = 65001
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.BodyName = utf-8
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.EncodingName = Unicode (UTF-8)
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.HeaderName = utf-8
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.WebName = utf-8
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.WindowsCodePage = 1200
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsBrowserDisplay = True
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsBrowserSave = True
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsMailNewsDisplay = True
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsMailNewsSave = True
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsSingleByte = False
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.EncoderFallback = System.Text.EncoderReplacementFallback
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.DecoderFallback = System.Text.DecoderReplacementFallback
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.IsReadOnly = True
2016-06-30 20:05:29.8279 DEBUG this.HeaderEncoding.CodePage = 65001
2016-06-30 20:05:29.8279 DEBUG this.Cache = System.Web.HttpCachePolicy
2016-06-30 20:05:29.8434 DEBUG this.IsClientConnected = True
2016-06-30 20:05:29.8434 DEBUG this.ClientDisconnectedToken = System.Threading.CancellationToken
2016-06-30 20:05:29.8434 DEBUG this.IsRequestBeingRedirected = False
2016-06-30 20:05:29.8434 DEBUG this.RedirectLocation = null
2016-06-30 20:05:29.8434 DEBUG this.Output = System.Web.HttpWriter
2016-06-30 20:05:29.8434 DEBUG this.OutputStream.CanRead = False
2016-06-30 20:05:29.8434 DEBUG this.OutputStream.CanSeek = False
2016-06-30 20:05:29.8434 DEBUG this.OutputStream.CanWrite = True
</code></pre>

<p>When I'm using the proxy, however, this is all Firefox reports as the headers received:</p>

<pre><code>Date: Fri, 01 Jul 2016 00:11:44 GMT
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
</code></pre>

<p>This leads to how I'm hosting my proxy. It is ran through IIS using an HttpModule and the site is configured to run all managed modules on requests. How can I get the browser to accept this response?</p>