title: HttpClient and PushStreamContent
body: <p>I use PushStreamContent with my REST API (ASP.NET Web API) and works great.
  The HttpClient can request a ressource and gets the HTTP-Response before the complete request is handled by the server (the server still writes to the push-stream).</p>
  
  <p>As HttpClient you have to do one little thing: Use HttpCompletionOption.ResponseHeadersRead.</p>
  
  <p>Now my question:
  Is it possible to to this the other way?
  From the HttpClient -> uploading data via a push-stream to the web api?</p>
  
  <p>I Implemented it as below, but the web api gets the request not before the client closes the stream.</p>
  
  <pre><code>         var asyncStream = new AsyncStream(fs);
           PushStreamContent streamContent = new PushStreamContent(asyncStream.WriteToStream);
           content.Add(streamContent);
  
           HttpResponseMessage response = await c.SendAsync(new HttpRequestMessage(new HttpMethod("POST"), "http://localhost/...") { Content = content }, HttpCompletionOption.ResponseHeadersRead);
  
           response.EnsureSuccessStatusCode();
  </code></pre>
  
  <p>The AsyncStream is my class with the delegate:</p>
  
  <pre><code>public async void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
  </code></pre>
  
  <p>This is necessary for the Push-Stream.</p>
  
  <p>Is this possible somehow? The HttpClient do not send the request to the web api until the last bytes are written to the stream...</p>
  
  <p>What do I have to do? Is the problem on the client side or maybe on the server / asp.net web api-side?</p>
  
  <p>Edit:
  This is the implemenation of WriteToStream (but I do not use a file from disk, is use a memorystream 'myMemoryStream' (passed in the constructor):</p>
  
  <pre><code>public void WriteToStream(Stream outputStream, HttpContent content, TransportContext context)
  {
      try
      {
          var buffer = new byte[4096];
  
          using (var stream = myMemoryStream)
          {
              var bytesRead = 1;
  
              while (bytesRead &gt; 0)
              {
                  bytesRead = video.Read(buffer, 0, buffer.Length);
                  outputStream.Write(buffer, 0, bytesRead);
              }
          }
      }
      catch (HttpException ex)
      {
          return;
      }
      finally
      {
          outputStream.Close();
      }
  }
  </code></pre>
  
  <p>Maybe I have to do something with: HttpContent content, TransportContext context ?</p>