title: How can I parse a raw HTTP response in .net?
body: <p>I've got a project which deals with byte streams, and some of them are HTTP responses. I need to parse a raw HTTP response from this byte stream.</p>
  <p>I can do this myself, but there must already be code that exists to do this, so I started looking at <a href="https://www.nuget.org/packages/Microsoft.AspNetCore.Server.Kestrel/" rel="nofollow noreferrer">Kestrel</a>, but I can't see any way to do what I'm attempting. Perhaps it's overkill for my needs any way.</p>
  <p>How can I parse a raw HTTP response in .net?</p>
  <p>Here's an example, decoded to ASCII:</p>
  <pre><code>HTTP/1.1 200 OK
  Content-Type: text/html
  Last-Modified: Sun, 17 Apr 2022 03:32:06 GMT
  Accept-Ranges: bytes
  ETag: &quot;374b9ab6b52d81:0&quot;
  Server: Microsoft-IIS/10.0
  X-Powered-By: ASP.NET
  Date: Wed, 27 Apr 2022 10:45:49 GMT
  Content-Length: 696
  
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot; /&gt;
  &lt;title&gt;IIS Windows&lt;/title&gt;
  &lt;style type=&quot;text/css&quot;&gt;
  &lt;!--
  body {
      color:#000000;
      background-color:#0072C6;
      margin:0;
  }
  
  #container {
      margin-left:auto;
      margin-right:auto;
      text-align:center;
      }
  
  a img {
      border:none;
  }
  
  --&gt;
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id=&quot;container&quot;&gt;
  &lt;a href=&quot;http://go.microsoft.com/fwlink/?linkid=66138&amp;amp;clcid=0x409&quot;&gt;&lt;img src=&quot;iisstart.png&quot; alt=&quot;IIS&quot; width=&quot;960&quot; height=&quot;600&quot; /&gt;&lt;/a&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>