title: Stop IResponseCookies.Append() from encoding cookies. dotnetcore 2.0
body: <p>We are building a dotnetcore 2.0 web app that receiving cookies from a legacy system via http and setting the cookies in the response.</p>
  
  <p>When I debug the app I can see that <code>cookie.value</code> is not url encoded but after calling append the set-cookie headers are url encoded. This is problematic as the legacy cookies need to be unencoded as legacy apps read them as they are.</p>
  
  <pre><code>    public static void AddCookie(this IResponseCookies cookies, Cookie cookie)
      {
          cookies.Append(cookie.Name, cookie.Value, new CookieOptions
          {
              Domain = cookie.Domain,               
              Expires = cookie.Expires == DateTime.MinValue ? null : (DateTimeOffset?) cookie.Expires,
              HttpOnly = cookie.HttpOnly,
              Path = cookie.Path,
              Secure = cookie.Secure
          });
      }
  </code></pre>
  
  <p>Is there a way to prevent them being encoded? A flag or setting somewhere?</p>
  
  <p>I tried writing an owin middleware but the set-cookie header is always empty.</p>
  
  <pre><code>public class CookieDecode
  {
      private readonly RequestDelegate _next;
  
      public CookieDecode(RequestDelegate next)
      {
          _next = next;
      }
  
      public async Task Invoke(HttpContext context)
      {
          var x = context.Response.Headers;
          var y = x["set-cookie"];
          //y is always empty
          await _next.Invoke(context);
      }
  }
  </code></pre>
  
  <p>Ideas?</p>